alexjercan/bugnet huggingface dataset:
Problem p01273 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main() {
  ios_base::sync_with_stdio(false);
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    vector<pipii> seq(m);
    for (int i = 0; i < m; ++i) {
      int t, s, d;
      cin >> t >> s >> d;
      --s;
      --d;
      seq[i] = pipii(t, pii(s, d));
    }
    sort(seq.begin(), seq.end());
    vector<int> s(m), d(m);
    for (int i = 0; i < m; ++i) {
      s[i] = seq[i].second.first;
      d[i] = seq[i].second.second;
    }
    vector<int> infect(n, -1);
    infect[0] = 0;
    for (int i = 0; i < m; ++i) {
      if (infect[s[i]] >= 0) {
        infect[d[i]] = i;
      }
    }
    int answer = 0;
    for (int i = 0; i < n; ++i) {
      if (infect[i] >= 0) {
        ++answer;
      }
    }
    cout << answer << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) {
      break;
    }
    vector<int> s(m), d(m);
    vector<int> infect(n, -1);
    infect[0] = 0;
    for (int i = 0; i < m; ++i) {
      int t, ls, ld;
      cin >> t >> ls >> ld;
      --t;
      --ls;
      --ld;
      s[t] = ls;
      d[t] = ld;
    }
    for (int i = 0; i < m; ++i) {
      if (infect[s[i]] >= 0) {
        infect[d[i]] = i;
      }
    }
    int answer = 0;
    for (int i = 0; i < n; ++i) {
      if (infect[i] >= 0) {
        ++answer;
      }
    }
    cout << answer << endl;
  }
  return 0;
}
Problem p01273 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long int n, m, i, k;
  while (cin >> n >> m, n != 0 || m != 0) {
    vector<long long int> v(20100, 0);
    long long int cnt = 1, data[20100][10] = {};
    long long int in[20100] = {};
    in[1] = 1;
    k = 0;
    for (i = 0; i < m; i++) {
      long long int t, s, g;
      cin >> t >> s >> g;
      data[i][0] = s;
      data[i][1] = g;
      v[k++] = t;
    }
    for (i = 0; i < m - 1; i++) {
      for (int j = m - 1; j > i; j--) {
        if (v[i] > v[j]) {
          swap(v[i], v[j]);
          swap(data[i], data[j]);
        }
      }
    }
    //    sort(v.begin(), v.begin() + m);
    for (i = 0; i < m; i++) {
      if (in[data[i][0]]) {
        if (in[data[i][1]] == 0) {
          cnt++;
          in[data[i][1]] = 1;
        }
      }
    }

    cout << cnt << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long int n, m, i, k;
  while (cin >> n >> m, n != 0 || m != 0) {
    vector<long long int> v(20100, 0);
    long long int cnt = 1, data[20100][10] = {};
    long long int in[20100] = {};
    in[1] = 1;
    k = 0;
    for (i = 0; i < m; i++) {
      long long int t, s, g;
      cin >> t >> s >> g;
      data[t][0] = s;
      data[t][1] = g;
      v[k++] = t;
    }
    sort(v.begin(), v.begin() + m);
    for (i = 0; i < m; i++) {
      if (in[data[v[i]][0]]) {
        if (in[data[v[i]][1]] == 0) {
          cnt++;
          in[data[v[i]][1]] = 1;
        }
      }
    }

    cout << cnt << endl;
  }
  return 0;
}
Problem p01273 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    vector<int> ts(m), ss(m), ds(m);
    for (int i = 0; i < m; i++) {
      cin >> ts[i] >> ss[i] >> ds[i];
      ss[i]--, ds[i]--;
    }

    map<int, int> ma;
    for (int i = 0; i < m; i++)
      ma[ts[i]] = i;

    vector<int> flg(n);
    fill(begin(flg), end(flg), false);
    flg[0] = 1;
    map<int, int>::iterator it = ma.begin();
    for (int i = 0; i < m; i++, it++) {
      int j = it->second;
      flg[ds[j]] |= flg[ss[j]];
    }

    cout << count(begin(flg), end(flg), true) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    vector<int> ss(m), ds(m);
    for (int i = 0; i < m; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      t--, s--, d--;
      ss[t] = s, ds[t] = d;
    }

    vector<int> flg(n);
    fill(begin(flg), end(flg), false);
    flg[0] = 1;
    for (int i = 0; i < m; i++)
      flg[ds[i]] |= flg[ss[i]];

    cout << count(begin(flg), end(flg), true) << endl;
  }

  return 0;
}
Problem p01273 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct P {
  int t;
  int s;
  int d;
};

int cmp(const void *a, const void *b) {
  struct P *tmp1 = (struct P *)a;
  struct P *tmp2 = (struct P *)b;
  return tmp1->t - tmp2->t;
}

int main(void) {
  int n, m, count, i, p[20000];
  struct P data[20000];
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    memset(p, 0, sizeof(p));
    p[0] = 1;
    for (i = 0; i < m; i++)
      scanf("%d%d%d", &data[i].t, &data[i].s, &data[i].d);
    qsort(data, m, sizeof(data[0]), cmp);
    for (i = 0; i < m; i++) {
      if (p[data[i].s - 1])
        p[data[i].d - 1] = 1;
    }
    count = 0;
    for (i = 0; i < n; i++)
      if (p[i])
        count++;
    printf("%d\\n", count);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct P {
  int t;
  int s;
  int d;
};

int cmp(const void *a, const void *b) {
  struct P *tmp1 = (struct P *)a;
  struct P *tmp2 = (struct P *)b;
  return tmp1->t - tmp2->t;
}

int main(void) {
  int n, m, count, i, j, p[20000];
  struct P data[20000];
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    memset(p, 0, sizeof(p));
    p[0] = 1;
    for (i = 0; i < m; i++)
      scanf("%d%d%d", &data[i].t, &data[i].s, &data[i].d);
    qsort(data, m, sizeof(data), cmp);
    for (i = 0; i < m; i++) {
      if (p[data[i].s - 1])
        p[data[i].d - 1] = 1;
    }
    count = 0;
    for (i = 0; i < n; i++)
      if (p[i])
        count++;
    printf("%d\\n", count);
  }
  return 0;
}
Problem p01273 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int N, M;
vector<pair<int, P>> vec;
bool f[20004];

void solve() {
  rep(i, 20004) f[i] = false;
  f[1] = true;
  vec.clear();

  rep(i, M) {
    int t, s, d;
    cin >> t >> s >> d;
    vec.pb(mp(t, mp(s, d)));
  }
  sort(all(vec));

  rep(i, vec.size()) {
    int t = vec[i].fr;
    int s = vec[i].sc.fr;
    int d = vec[i].sc.sc;
    if (f[s])
      f[d] = true;
  }
  int ans = 0;
  rep(i, 20004) if (f[i]) ans++;
  cout << ans << endl;
}

int main() {
  while (cin >> N >> M) {
    if (N + M == 0)
      break;
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int N, M;
vector<int> G[20004];
bool f[20004];

void dfs(int v) {
  rep(i, G[v].size()) {
    int e = G[v][i];
    if (!f[e]) {
      dfs(e);
      f[e] = true;
    }
  }
}
void solve() {
  rep(i, 20004) G[i].clear();
  rep(i, 20004) f[i] = false;

  rep(i, M) {
    int t, s, d;
    cin >> t >> s >> d;
    G[s].pb(d);
  }
  dfs(1);
  f[1] = true;

  int ans = 0;
  rep(i, 20004) if (f[i]) ans++;
  cout << ans << endl;
}

int main() {
  while (cin >> N >> M) {
    if (N + M == 0)
      break;
    solve();
  }
  return 0;
}
Problem p01273 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() {
  int n, m;
  while (cin >> n >> m && !(n == 0 && m == 0)) {
    pll a[20000], b[20000];
    REP(i, m) {
      ll x, y, z;
      cin >> x >> y >> z;
      y -= 1;
      z -= 1;
      a[i] = make_pair(x, y);
      b[i] = make_pair(x, z);
    }
    sort(a, a + m);
    sort(b, b + m);

    bool inf[20000] = {};
    inf[0] = true;
    // REP(i,n)cout<<inf[i];cout<<endl;
    REP(i, m) {
      if (inf[a[i].second]) {
        inf[b[i].second] = true;
      }
    }
    // REP(i,n)cout<<inf[i];cout<<endl;
    int ans(0);
    REP(i, n) ans += inf[i];

    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() {
  int n, m;
  while (cin >> n >> m && !(n == 0 && m == 0)) {
    pll a[10000], b[10000];
    REP(i, m) {
      ll x, y, z;
      cin >> x >> y >> z;
      y -= 1;
      z -= 1;
      a[i] = make_pair(x, y);
      b[i] = make_pair(x, z);
    }
    sort(a, a + m);
    sort(b, b + m);

    bool inf[10000] = {};
    inf[0] = true;
    // REP(i,n)cout<<inf[i];cout<<endl;
    REP(i, m) {
      if (inf[a[i].second]) {
        inf[b[i].second] = true;
      }
    }
    // REP(i,n)cout<<inf[i];cout<<endl;
    int ans(0);
    REP(i, n) ans += inf[i];

    cout << ans << endl;
  }
  return 0;
}
Problem p01273 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct Packet {
  int t, s, d;

  Packet() = default;
  Packet(int t, int s, int d) : t(t), s(s), d(d) {}

  bool operator<(const Packet &p) const { return t < p.t; }
};

int main() {
  while (true) {
    int N, M;
    cin >> N >> M;

    if (N + M == 0) {
      break;
    }

    bool infected[20001] = {true};

    vector<Packet> packet(M);
    for (int i = 0; i < M; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      packet[i] = Packet(t, s - 1, d - 1);
    }
    sort(packet.begin(), packet.end());

    for (int i = 0; i < M; i++) {
      if (infected[packet[i].s]) {
        infected[packet[i].d] = true;
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (infected[i]) {
        ans++;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct Packet {
  int t, s, d;

  Packet() = default;
  Packet(int t, int s, int d) : t(t), s(s), d(d) {}

  bool operator<(const Packet &p) const { return t < p.t; }
};

int main() {
  while (true) {
    int N, M;
    cin >> N >> M;

    if (N + M == 0) {
      break;
    }

    bool infected[20001] = {true};

    vector<Packet> packet(M);
    for (int i = 0; i < M; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      packet[i] = Packet(t, s - 1, d - 1);
    }
    sort(packet.begin(), packet.end());

    for (int i = 0; i < M; i++) {
      if (infected[packet[i].s]) {
        infected[packet[i].t] = true;
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (infected[i]) {
        ans++;
      }
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p01274 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int HP[100], M;
long long dp1[100001], dp2[100001];

int solve(int N) {
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));

  for (int i = 0; i < N; i++) {
    cin >> HP[i];
  }
  cin >> M;

  bool end = false;
  while (M--) {
    string Name, Target;
    int MP, Damage;
    cin >> Name >> MP >> Target >> Damage;
    if (MP == 0) {
      if (Damage > 0)
        end = true;
      continue;
    }
    long long *dp = Target.size() == 3 ? dp1 : dp2;
    for (int i = MP; i <= 100000; i++) {
      dp[i] = max(dp[i], dp[i - MP] + Damage);
    }
  }
  if (end)
    return (0);

  int best = 1 << 30;
  for (int i = 0; i <= 100000; i++) {
    int ret = 0;
    for (int j = 0; j < N; j++) {
      ret += lower_bound(dp2, dp2 + 100001, HP[j] - dp1[i]) - dp2;
    }
    best = min(best, i + ret);
  }
  return (best);
}

int main() {
  int N;
  while (cin >> N, N) {
    cout << solve(N) << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int HP[100], M;
long long dp1[100001], dp2[100001];

int solve(int N) {
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));

  for (int i = 0; i < N; i++) {
    cin >> HP[i];
  }
  cin >> M;

  bool end = false;
  while (M--) {
    string Name, Target;
    int MP, Damage;
    cin >> Name >> MP >> Target >> Damage;
    if (MP == 0) {
      if (Damage > 0)
        end = true;
      continue;
    }
    long long *dp = Target.size() == 3 ? dp1 : dp2;
    for (int i = MP; i <= 100000; i++) {
      dp[i] = max(dp[i], dp[i - MP] + Damage);
    }
  }
  if (end)
    return (0);

  int best = 1 << 30, pos = *max_element(HP, HP + N);
  for (int i = 0; i <= 100000 && HP[i] <= pos; i++) {
    int ret = 0;
    for (int j = 0; j < N; j++) {
      ret += lower_bound(dp2, dp2 + 100001, HP[j] - dp1[i]) - dp2;
    }
    best = min(best, i + ret);
  }
  return (best);
}

int main() {
  int N;
  while (cin >> N, N) {
    cout << solve(N) << endl;
  }
}
Problem p01274 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1e5 + 1;
const long long int inf = 1e16;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<int> hp(n);
    for (int i = 0; i < n; i++)
      cin >> hp[i];

    int m;
    cin >> m;
    vector<long long int> mp(m), range(m), damage(m);
    for (int i = 0; i < m; i++) {
      string name, r;
      cin >> name >> mp[i] >> r >> damage[i];
      if (r == "Single") {
        range[i] = 0;
      } else {
        range[i] = 1;
      }
    }

    vector<vector<long long int>> dp(2, vector<long long int>(MAX, inf));
    for (int d = 0; d < 2; d++) {
      dp[d][0] = 0;
      for (int i = 0; i < m; i++) {
        if (range[i] != d || damage[i] == 0)
          continue;
        for (int j = 0; j < MAX; j++) {
          dp[d][j] = min(dp[d][j], (j + damage[i] - 1) / damage[i] * mp[i]);
          if (j - damage[i] > 0) {
            dp[d][j] = min(dp[d][j], dp[d][j - damage[i]] + mp[i]);
          }
        }
      }
    }

    long long int ans = inf;
    for (int i = 0; i < MAX; i++) {
      long long int cost = dp[1][i];
      for (int j = 0; j < n; j++) {
        if (hp[j] - i > 0) {
          cost += dp[0][hp[j] - i];
        }
      }
      ans = min(ans, cost);
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1e5 + 1;
const int inf = 1e9;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<int> hp(n);
    for (int i = 0; i < n; i++)
      cin >> hp[i];

    int m;
    cin >> m;
    vector<int> mp(m), range(m), damage(m);
    for (int i = 0; i < m; i++) {
      string name, r;
      cin >> name >> mp[i] >> r >> damage[i];
      if (r == "Single") {
        range[i] = 0;
      } else {
        range[i] = 1;
      }
    }

    vector<vector<int>> dp(2, vector<int>(MAX, inf));
    for (int d = 0; d < 2; d++) {
      for (int i = 0; i < m; i++) {
        if (range[i] != d)
          continue;
        for (int j = 0; j < MAX; j++) {
          dp[d][j] = min(dp[d][j], (j + damage[i] - 1) / damage[i] * mp[i]);
          if (j - damage[i] > 0) {
            dp[d][j] = min(dp[d][j], dp[d][j - damage[i]] + mp[i]);
          }
        }
      }
    }

    int ans = inf;
    for (int i = 0; i < MAX; i++) {
      int cost = dp[1][i];
      for (int j = 0; j < n; j++) {
        if (hp[j] - i > 0) {
          cost += dp[0][hp[j] - i];
        }
      }
      ans = min(ans, cost);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01274 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int single[100010] = {};
int multi[100010] = {};
int hp[110];
int main() {
  int N;
  while (cin >> N && N) {
    for (int i = 0; i < 100010; i++)
      single[i] = 1e9;
    for (int i = 0; i < 100010; i++)
      multi[i] = 1e9;
    single[0] = multi[0] = 0;
    for (int i = 0; i < N; i++)
      cin >> hp[i];
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
      string name;
      int mp;
      string target;
      int dmg;
      cin >> name >> mp >> target >> dmg;
      if (target == "Single") {
        for (int j = 0; j <= 100000; j++) {
          int t = min(100000, j + dmg);
          single[t] = min(single[t], single[j] + mp);
        }
      } else {
        for (int j = 0; j <= 100000; j++) {
          int t = min(100000, j + dmg);
          multi[t] = min(multi[t], multi[j] + mp);
        }
      }
    }
    for (int j = 100000; j >= 0; j--) {
      single[j] = min(single[j + 1], single[j]);
      multi[j] = min(multi[j + 1], multi[j]);
    }

    long long ans = 1e9;
    for (int i = 0; i <= 100000; i++) {
      long long sub = multi[i];
      for (int j = 0; j < N; j++) {
        int r = max(0, hp[j] - i);
        sub += single[r];
      }
      ans = min(sub, ans);
    }
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int single[200010] = {};
int multi[200010] = {};
int hp[110];
int main() {
  int N;
  while (cin >> N && N) {
    for (int i = 0; i < 100010; i++)
      single[i] = 1e9;
    for (int i = 0; i < 100010; i++)
      multi[i] = 1e9;
    single[0] = multi[0] = 0;
    for (int i = 0; i < N; i++)
      cin >> hp[i];
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
      string name;
      int mp;
      string target;
      int dmg;
      cin >> name >> mp >> target >> dmg;
      if (target == "Single") {

        for (int j = 0; j <= 100000; j++) {
          int t = min(100000, j + dmg);
          single[t] = min(single[j + dmg], single[j] + mp);
        }
      } else {
        for (int j = 0; j <= 100000; j++) {
          int t = min(100000, j + dmg);
          multi[t] = min(multi[t], multi[j] + mp);
        }
      }
    }
    for (int j = 100000; j >= 0; j--) {
      single[j] = min(single[j + 1], single[j]);
      multi[j] = min(multi[j + 1], multi[j]);
    }

    long long ans = 1e9;
    for (int i = 0; i <= 100000; i++) {
      long long sub = multi[i];
      for (int j = 0; j < N; j++) {
        int r = max(0, hp[j] - i);
        sub += single[r];
      }
      ans = min(sub, ans);
    }
    cout << ans << endl;
  }
}
Problem p01274 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int multi[100010], single[100010], hp[110];

int main() {
  int N;
  while (cin >> N && N) {
    for (int i = 0; i < 100010; i++) {
      multi[i] = 1e9;
      single[i] = 1e9;
    }
    multi[0] = 0;
    single[0] = 0;
    for (int i = 0; i < N; i++)
      cin >> hp[i];
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
      string name;
      int mp;
      string command;
      int dmp;
      cin >> name >> mp >> command >> dmp;
      if (command == "Single") {
        for (int j = 0; j <= 100000; j++) {
          int s = min(100000, j + dmp);
          single[s] = min(single[s], single[j] + mp);
        }
      } else {
        for (int j = 0; j <= 100000; j++) {
          int s = min(100000, j + dmp);
          multi[s] = min(multi[s], multi[j] + mp);
        }
      }
    }
    for (int i = 100000; i >= 0; i--) {
      multi[i] = min(multi[i], multi[i + 1]);
      single[i] = min(single[i], single[i + 1]);
    }
    long long ans = 1e9;
    for (int i = 0; i <= 100000; i++) {
      long long u = multi[i];
      for (int j = 0; j < N; j++) {
        int v = max(0, hp[j] - i);
        u += single[v];
      }
      ans = min(u, ans);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int multi[100010], single[100010], hp[110];

int main() {
  int N;
  while (cin >> N && N) {
    for (int i = 0; i < 100010; i++) {
      multi[i] = 1e9;
      single[i] = 1e9;
    }
    multi[0] = 0;
    single[0] = 0;
    for (int i = 0; i < N; i++)
      cin >> hp[i];
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
      string name;
      int mp;
      string command;
      int dmp;
      cin >> name >> mp >> command >> dmp;
      if (command == "Single") {
        for (int j = 0; j <= 100000; j++) {
          int s = min(100000, j + dmp);
          single[s] = min(single[s], single[j] + mp);
        }
      } else {
        for (int j = 0; j <= 100000; j++) {
          int s = min(100000, j + dmp);
          multi[s] = min(multi[s], multi[j] + mp);
        }
      }
    }
    for (int i = 100000; i >= 0; i--) {
      multi[i] = min(multi[i], multi[i + 1]);
      single[i] = min(single[i], single[i + 1]);
    }
    long long ans = 1e9;
    for (int i = 0; i <= 100000; i++) {
      long long u = multi[i];
      for (int j = 0; j < N; j++) {
        int v = min(0, hp[j] - i);
        u += single[v];
      }
      ans = min(u, ans);
    }
    cout << ans << endl;
  }
  return 0;
}