#include #include #include using namespace std; const int MAX_N = 100; const int MAX_B = 1000; int main () { int j, k, somma, temp, n, B, numeri[MAX_N]; ifstream fin ("input.txt"); fin >> n; fin >> B; for (j = 0; j < n; j++) fin >> numeri[j]; fin.close (); sort (numeri, numeri + n); temp = 0; somma = 0; k = 0; j = 0; while (j < n) { temp += numeri[j]; j ++; while (temp > B && k < j) { temp -= numeri[k]; k ++; } somma = max (somma, temp); } while (k < n) { temp -= numeri[k]; k ++; if (temp <= B) somma = max (somma, temp); } ofstream fout("output.txt"); fout << somma << endl; fout.close(); return 0; }