Problem p00169 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

// #define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  { cerr << #o << " " << o << endl; }
#define dumpc(o)                                                               \\
  {                                                                            \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

// split delimiter??§?????????
vector<string> split(const string &input, char delimiter) {
  vector<string> ret;
  istringstream stream(input);
  string s;
  while (getline(stream, s, delimiter))
    ret.push_back(s);
  return ret;
}
#define MAX 50
signed main() {
  bool a[2][1000] = {};
  for (string s; getline(cin, s) && s != "0";) {
    fill(a[0], a[2], false);
    a[0][0] = true;
    vector<string> t = split(s, ' ');
    rep(i, 0, t.size()) {
      rep(j, 0, MAX) a[(i + 1) % 2][j] = false;
      rep(j, 0, MAX - 20) {
        if (stoi(t[i]) <= 10)
          if (a[i % 2][j])
            a[(i + 1) % 2][stoi(t[i]) + j] = true;
        if (stoi(t[i]) >= 11)
          if (a[i % 2][j])
            a[(i + 1) % 2][10 + j] = true;
        if (stoi(t[i]) == 1)
          if (a[i % 2][j])
            a[(i + 1) % 2][11 + j] = true;
      }
    }
    a[t.size() % 2][0] = true;
    rrep(i, 0, 22) {
      if (a[t.size() % 2][i]) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

// #define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  { cerr << #o << " " << o << endl; }
#define dumpc(o)                                                               \\
  {                                                                            \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

// split delimiter??§?????????
vector<string> split(const string &input, char delimiter) {
  vector<string> ret;
  istringstream stream(input);
  string s;
  while (getline(stream, s, delimiter))
    ret.push_back(s);
  return ret;
}

signed main() {
  bool a[50][50] = {};
  for (string s; getline(cin, s) && s != "0";) {
    fill(a[0], a[50], false);
    a[0][0] = true;
    vector<string> t = split(s, ' ');
    rep(i, 0, t.size()) {
      rep(j, 0, 30) {
        // if (stoi(t[i]) <= 10)
        //	if (a[i][j])a[i + 1][stoi(t[i]) + j] = true;
        // if (stoi(t[i]) >= 11)
        //	if (a[i][j])a[i + 1][10 + j] = true;
        if (stoi(t[i]) == 1)
          if (a[i][j])
            a[i + 1][11 + j] = true;
      }
    }
    rrep(i, 0, 22) {
      if (a[t.size()][i]) {
        cout << i << endl;
        break;
      }
      if (i == 0)
        cout << 0 << endl;
    }
  }
  return 0;
}