func_code_string: #include <bits/stdc++.h>   using namespace std;   bool solve(const vector<int>& hps, const vector<int>& hero, vector<int>& soln,              int frm, int dir) {     soln.clear();     int n = hps.size();     if (n == 0) return true;     vector<int> heroes;     heroes.push_back(0);     for (int i = 1; i < n; i++) {       if (hero[i]) heroes.push_back(i);     }     int h = heroes.size();     if (h == 1) {       if (hero[0]) {         soln.push_back(frm);       }       return true;     }     vector<int> dp(h, -1);     dp[0] = 0;     for (int i = 1; i < h; i++) {       int health = hero[heroes[i]];       assert(health > 0);       for (int j = i - 1; j >= 0; j--) {         bool gone = false;         for (int k = heroes[j + 1] - 1; k >= heroes[j]; k--) {           health += hps[k];           if (health < 0) {             gone = true;             break;           }         }         if (gone) break;         if (dp[j] != -1) {           dp[i] = j;           break;         }       }     }     if (dp[h - 1] == -1) return false;     vector<int> taken(h, 0);     int x = h - 1;     while (1) {       taken[x] = 1;       if (hero[heroes[x]]) soln.push_back(x);       if (x == 0) break;       x = dp[x];     }     reverse(soln.begin(), soln.end());     for (int i = 0; i < h; i++)       if (!taken[i]) soln.push_back(i);     for (int& x : soln) {       x = heroes[x];       if (dir > 0) {         x += frm;       } else {         x = frm - x;       }     }     return true;   }   const int MAXN = 107;   int heroHealth[MAXN];   int healthPnts[MAXN];   int heroMap[MAXN];   int n;   bool checkDirection(int rp, int dir, int bahir, vector<int>& soln) {     vector<int> hps;     vector<int> hero;     for (int i = rp + bahir * dir; i <= n && i > 0; i += dir) {       hps.push_back(healthPnts[i]);       hero.push_back(heroHealth[i]);     }     return solve(hps, hero, soln, rp + bahir * dir, dir);   }   bool rally(int rp, vector<int>& soln) {     soln.clear();     vector<int> bamsoln;     vector<int> dansoln;     bool x = checkDirection(rp, 1, 0, dansoln);     bool y = checkDirection(rp, -1, 1, bamsoln);     if (x && y) {       if (healthPnts[rp] >= 0 || dansoln.size() > 0) {         for (int g : dansoln) {           soln.push_back(heroMap[g]);         }         for (int g : bamsoln) {           soln.push_back(heroMap[g]);         }         return true;       }     }     if (healthPnts[rp] < 0) {       x = checkDirection(rp, 1, 1, dansoln);       y = checkDirection(rp, -1, 0, bamsoln);       if (x && y && bamsoln.size() > 0) {         for (int g : bamsoln) {           soln.push_back(heroMap[g]);         }         for (int g : dansoln) {           soln.push_back(heroMap[g]);         }         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     int m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int s, h;       cin >> s >> h;       heroHealth[s] = h;       heroMap[s] = i;     }     for (int i = 1; i <= n; i++) {       cin >> healthPnts[i];     }     vector<int> soln;     for (int rp = 1; rp <= n; rp++) {       if (rally(rp, soln)) {         cout << rp << endl;         for (int x : soln) cout << x <<    ;         return 0;       }     }     cout << -1 << endl;     return 0;   }   