func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, s[111];   int f[20][1 << 20];   int bitc[1 << 20];   int act[22];   int who[22];   int picks[22];   inline void upd_max(int i, int j, int val) {     if (f[i][j] > 1000000000)       f[i][j] = val;     else       f[i][j] = max(f[i][j], val);   }   inline void upd_min(int i, int j, int val) {     if (f[i][j] > 1000000000)       f[i][j] = val;     else       f[i][j] = min(f[i][j], val);   }   int solve(int step, int ban) {     if (step == n) return 0;     if (f[step][ban] < 1000000000) return f[step][ban];     int pick, left;     for (pick = 0, left = picks[step];; ++pick) {       if (!(ban & (1 << pick))) --left;       if (left == -1) break;     }     if (act[step] == 1) {       if (who[step] == 1) {         upd_max(step, ban, solve(step + 1, ban) + s[pick]);       } else {         upd_min(step, ban, solve(step + 1, ban) - s[pick]);       }     } else {       for (; pick < n; ++pick) {         if (!(ban & (1 << pick))) {           if (who[step] == 1) {             upd_max(step, ban, solve(step + 1, ban | (1 << pick)));           } else {             upd_min(step, ban, solve(step + 1, ban | (1 << pick)));           }         }       }     }     return f[step][ban];   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> s[i];     sort(s, s + n);     reverse(s, s + n);     cin >> m;     if (n > m) n = m;     for (int i = 0; i < m; ++i) {       char ch;       cin >> ch;       if (ch ==  p )         act[i] = 1;       else         act[i] = 0;       cin >> who[i];       if (i) picks[i] = picks[i - 1] + act[i - 1];     }     memset(f, 63, sizeof(f));     bitc[0] = 0;     for (int i = 1; i < (1 << n); ++i) {       bitc[i] = bitc[i / 2] + i % 2;     }     cout << solve(0, 0) << endl;   }   