1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <iostream> #include <vector> using namespace std; int main() { int n, m, result = 0; vector<int> v; cin >> n >> m; for (int i = 0; i < n; i++) { int t; cin >> t; v.push_back(t); } for (int i = 0; i < n – 2; i++) for (int j = i + 1; j < n – 1; j++) for (int k = j + 1; k < n ; k++) { int sum = v[i] + v[j] + v[k]; if (sum > m) continue; if (m – sum < m – result || result == 0) result = sum; } cout << result << endl; return 0; } | cs |