func_code_string: #include <bits/stdc++.h>   using namespace std;   long long vet[9], used[9], available[9];   int dp[100][32];   int dp2[100][32];   vector<int> itens, itens2;   void comp() {     for (int i = 1; i <= 8; i++) {       long long j = 1;       used[i] = min(used[i], (long long)32 / i);       while (used[i]) {         itens.push_back(min(used[i], j) * i);         used[i] -= min(used[i], j);         j <<= 1;       }       j = 1;       available[i] = min(available[i], (long long)32 / i);       while (available[i]) {         itens2.push_back(min(available[i], j) * i);         available[i] -= min(available[i], j);         j <<= 1;       }     }     dp[0][0] = dp2[0][0] = 1;     for (int i = 0; i < itens.size(); i++) {       for (int j = 0; j < 32; j++) {         dp[i + 1][j] |= dp[i][j];         if (j >= itens[i]) dp[i + 1][j] |= dp[i][j - itens[i]];       }     }     for (int i = 0; i < itens2.size(); i++) {       for (int j = 0; j < 32; j++) {         dp2[i + 1][j] |= dp2[i][j];         if (j >= itens2[i]) dp2[i + 1][j] |= dp2[i][j - itens2[i]];       }     }   }   int consegue(int x) {     for (int i = 0; i < 32 - x; i++)       if (dp2[itens2.size()][i] && dp[itens.size()][x + i]) return 1;     return 0;   }   int main() {     long long W, total = 0;     scanf( %lld , &W);     for (int i = 1; i <= 8; i++) {       scanf( %lld , &vet[i]);       total += i * vet[i];     }     if (total <= W)       printf( %lld n , total);     else {       for (int i = 1; i <= 8; i++) used[i] = vet[i];       for (int i = 8; i >= 1; i--) {         if (total - i * used[i] >= W) {           total -= i * used[i];           available[i] = used[i];           used[i] = 0;         } else {           long long d = (total - W) / i;           total -= d * i;           used[i] -= d;           available[i] = d;         }       }       comp();       for (long long z = W; z >= max(0LL, W - 8); z--) {         int x = total - z;         if (consegue(x)) {           return !printf( %lld n , z);         }       }     }     return 0;   }   