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

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

int main() {
  string str;
  while (getline(cin, str) && str != "0") {
    int ans = 0, one = 0;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] != ' ') {
        if (str[i] == '1') {
          if (str[i + 1] >= '0') {
            ans += 10;
            i++;
          } else
            one++, ans++;
        } else
          ans += str[i] - '0';
      }
    }
    for (int i = 0; i < one; i++) {
      if (ans + 10 < 22)
        ans += 10;
    }
    if (ans > 21)
      ans = 0;
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

void solve() {
  string str;
  while (getline(cin, str)) {
    if (str[0] == '0') {
      return;
    }
    vector<int> Vec;
    string temp;
    int size = str.size();
    for (int i = 0; i < size; ++i) {
      if (str[i] == ' ') {
        int a;
        int multi = 1;
        int size2 = temp.size();
        for (int i = size2 - 1; i >= 0; --i) {
          a = (temp[i] - '0') * multi;
          multi *= 10;
        }
        Vec.push_back(a);
        temp.clear();
      } else {
        temp += str[i];
      }
    }
    int a;
    int multi = 1;
    int size2 = temp.size();
    for (int i = size2 - 1; i >= 0; --i) {
      a = (temp[i] - '0') * multi;
      multi *= 10;
    }
    Vec.push_back(a);
    temp.clear();

    int max;
    queue<int> Que;
    queue<int> NextQue;
    if (Vec[0] == 1) {
      Que.push(1);
      Que.push(11);
    } else if (10 <= Vec[0] && Vec[0] < 14) {
      Que.push(10);
    } else {
      Que.push(Vec[0]);
    }
    size = Vec.size();
    int pos = 1;
    while (pos != size) {
      while (!Que.empty()) {
        int Front;
        if (Vec[pos] == 1) {
          Front = Que.front() + 1;
          NextQue.push(Front);
          Front = Que.front() + 11;
          NextQue.push(Front);
        } else if (10 <= Vec[pos] && Vec[pos] < 14) {
          Front = Que.front() + 10;
          NextQue.push(Front);
        } else {
          Front = Que.front() + Vec[pos];
          NextQue.push(Front);
        }
        Que.pop();
      }
      while (!NextQue.empty()) {
        Que.push(NextQue.front());
        NextQue.pop();
      }
      pos++;
    }
    if (Que.size() == 1) {
      if (Que.front() > 21) {
        max = 0;
      } else {
        max = Que.front();
      }
    } else {
      vector<int> result;
      while (!Que.empty()) {
        result.push_back(Que.front());
        Que.pop();
      }
      sort(result.begin(), result.end());
      max = result[0];
      size = result.size();
      for (int i = 0; i < size; ++i) {
        if (result[i] <= 21) {
          max = result[i];
        }
      }
    }
    cout << max << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p00169 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <deque>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main(void) {
  string str;

  while (getline(cin, str)) {
    deque<int> q;
    int tmp;
    istringstream iss(str);
    iss >> tmp;
    if (tmp == 0)
      break;
    if (tmp == 1) {
      q.push_back(1);
      q.push_back(11);
    } else if (tmp >= 10) {
      q.push_back(10);
    } else {
      q.push_back(tmp);
    }

    while (iss >> tmp) {
      int times = q.size();
      for (int i = 0; i < times; i++) {
        if (tmp == 1) {
          if (q.front() + 1 <= 21) {
            q.push_back(q.front() + 1);
          }
          if (q.front() + 11 <= 21) {
            q.push_back(q.front() + 11);
          }
        } else if (tmp >= 10) {
          if (q.front() + 10 <= 21) {
            q.push_back(q.front() + 10);
          }
        } else {
          if (q.front() + tmp <= 21) {
            q.push_back(q.front() + tmp);
          }
        }
        q.pop_front();
      }
    }

    int ret = 0;
    while (!q.empty()) {
      if (q.front() >= 22) {
        // do nothing
      } else if (q.front() > ret) {
        ret = q.front();
      }
      q.pop_front();
    }
    cout << ret << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <deque>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main(void) {
  string str;

  while (getline(cin, str)) {
    deque<int> q;
    int tmp;
    istringstream iss(str);
    iss >> tmp;
    if (tmp == 0)
      break;
    if (tmp == 1) {
      q.push_back(1);
      q.push_back(11);
    } else if (tmp >= 10) {
      q.push_back(10);
    } else {
      q.push_back(tmp);
    }

    while (iss >> tmp) {
      int times = q.size();
      for (int i = 0; i < times; i++) {
        if (tmp == 1) {
          q.push_back(q.front() + 1);
          q.push_back(q.front() + 11);
        } else if (tmp >= 10) {
          q.push_back(q.front() + 10);
        } else {
          q.push_back(q.front() + tmp);
        }
        q.pop_front();
      }
    }

    int ret = 0;
    while (!q.empty()) {
      if (q.front() >= 22) {
        // do nothing
      } else if (q.front() > ret) {
        ret = q.front();
      }
      q.pop_front();
    }
    cout << ret << endl;
  }
  return 0;
}
Problem p00169 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  string S;
  while (getline(cin, S)) {
    priority_queue<int, vector<int>, greater<int>> pq[2];
    pq[0].push(0);
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
      if (i == 0 || S[i] == ' ') {
        int n = stoi(&S[i]);
        if (n == 0)
          return 0;
        while (!pq[cnt & 1].empty()) {
          int pq_c = pq[cnt & 1].top();
          pq[cnt & 1].pop();
          if (pq_c > 21)
            continue;
          if (n == 1)
            pq[(cnt + 1) & 1].push(pq_c + 1), pq[(cnt + 1) & 1].push(pq_c + 11);
          else if (n < 10)
            pq[(cnt + 1) & 1].push(pq_c + n);
          else
            pq[(cnt + 1) & 1].push(pq_c + 10);
        }
        cnt++;
      }
    }
    int ans = 0;
    while (!pq[cnt & 1].empty()) {
      if (pq[cnt & 1].top() <= 21)
        ans = max(ans, pq[cnt & 1].top());
      pq[cnt & 1].pop();
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  string S;
  while (getline(cin, S)) {
    priority_queue<int, vector<int>, greater<int>> pq[2];
    pq[0].push(0);
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
      if (i == 0 || S[i] == ' ') {
        int n = stoi(&S[i]);
        if (n == 0)
          return 0;
        while (!pq[cnt & 1].empty()) {
          int pq_c = pq[cnt & 1].top();
          pq[cnt & 1].pop();
          if (n == 1)
            pq[(cnt + 1) & 1].push(pq_c + 1), pq[(cnt + 1) & 1].push(pq_c + 11);
          else if (n < 10)
            pq[(cnt + 1) & 1].push(pq_c + n);
          else
            pq[(cnt + 1) & 1].push(pq_c + 10);
        }
        cnt++;
      }
    }
    int ans = 0;
    while (!pq[cnt & 1].empty()) {
      if (pq[cnt & 1].top() <= 21)
        ans = max(ans, pq[cnt & 1].top());
      pq[cnt & 1].pop();
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00169 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int rec(int sum, const vector<int> &v, int k) {
  if (v.size() > 21)
    return 0;
  if (k == v.size())
    return sum <= 21 ? sum : 0;
  if (v[k] == 1)
    return max(rec(sum + 1, v, k + 1), rec(sum + 11, v, k + 1));
  else
    return rec(sum + v[k], v, k + 1);
}

int main() {
  string s;
  while (getline(cin, s) && s != "0") {
    stringstream ss(s);
    int a;
    vector<int> v;
    while (ss >> a) {
      v.push_back(min(a, 10));
    }
    cout << rec(0, v, 0) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int rec(int sum, const vector<int> &v, int k) {
  if (k == v.size())
    return sum <= 21 ? sum : 0;
  if (v[k] == 1)
    return max(rec(sum + 1, v, k + 1), rec(sum + 11, v, k + 1));
  else
    return rec(sum + v[k], v, k + 1);
}

int main() {
  string s;
  while (getline(cin, s) && s != "0") {
    stringstream ss(s);
    int a;
    vector<int> v;
    while (ss >> a) {
      v.push_back(min(a, 10));
    }
    cout << rec(0, v, 0) << endl;
  }
  return 0;
}
Problem p00170 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string f[11];
int n, s[11], w[11], p[11], q[11];
bool ok() {
  for (int i = 0; i < n - 1; i++) {
    int r = 0;
    for (int j = i + 1; j < n; j++)
      r += w[p[j]];
    if (r > s[p[i]])
      return false;
  }
  return true;
}
int main() {
  while (cin >> n, n) {
    for (int i = 0; i < n; i++)
      cin >> f[i] >> w[i] >> s[i];
    for (int i = 0; i < n; i++)
      p[i] = i, q[i] = -1;
    do {
      if (ok()) {
        if (q[0] == -1)
          for (int i = 0; i < n; i++)
            q[i] = p[i];
        else {
          int sum1 = 0, sum2 = 0;
          for (int i = 0; i < n; i++)
            sum1 += w[p[i]] * (i + 1), sum2 += w[q[i]] * (i + 1);
          if (sum1 < sum2)
            for (int i = 0; i < n; i++)
              q[i] = p[i];
        }
      }
    } while (next_permutation(p, p + n));
    for (int i = 0; i < n; i++)
      cout << f[q[i]] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string f[11];
int n, s[11], w[11], p[11], q[11];
bool ok() {
  for (int i = 0; i < n - 1; i++) {
    int r = 0;
    for (int j = i + 1; j < n; j++)
      r += w[j];
    if (r > s[i])
      return false;
  }
  return true;
}
int main() {
  while (cin >> n, n) {
    for (int i = 0; i < n; i++)
      cin >> f[i] >> w[i] >> s[i];
    for (int i = 0; i < n; i++)
      p[i] = i, q[i] = -1;
    do {
      if (ok()) {
        if (q[0] == -1)
          for (int i = 0; i < n; i++)
            q[i] = p[i];
        else {
          int sum1 = 0, sum2 = 0;
          for (int i = 0; i < n; i++)
            sum1 += w[p[i]] * (i + 1), sum2 += w[q[i]] * (i + 1);
          if (sum1 < sum2)
            for (int i = 0; i < n; i++)
              q[i] = p[i];
        }
      }
    } while (p, p + n);
    for (int i = 0; i < n; i++)
      cout << s[q[i]] << endl;
  }
}
Problem p00170 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const double EPS = 1e-6;

int main(void) {
  int N;
  while (cin >> N, N) {
    ;
    vector<string> F(N);
    VI W(N), S(N);
    for (int i = 0; i < N; i++) {
      cin >> F[i] >> W[i] >> S[i];
    }

    VI p(N);
    iota(p.begin(), p.end(), 0);

    double ans = 1e+8;
    VI best_p(p.begin(), p.end());

    do {
      double g = 0, gt = 0;
      for (int i = 0; i < N; i++) {
        g += (i + 1) * W[p[i]];
        gt += W[p[i]];
      }
      g /= gt;

      if (g - EPS > ans) {
        continue;
      }

      bool flg = true;
      for (int i = N - 1; i >= 0; i--) {
        int sum = 0;
        for (int j = i + 1; j < N; j++) {
          sum += W[p[j]];
        }
        flg &= sum <= S[p[i]];
      }

      if (flg && g < ans + EPS) {
        ans = g;
        swap(best_p, p);
      }
    } while (next_permutation(p.begin(), p.end()));

    for (auto i : best_p) {
      cout << F[i] << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const double EPS = 1e-6;

int main(void) {
  int N;
  while (cin >> N, N) {
    ;
    vector<string> F(N);
    VI W(N), S(N);
    for (int i = 0; i < N; i++) {
      cin >> F[i] >> W[i] >> S[i];
    }

    VI p(N);
    iota(p.begin(), p.end(), 0);

    double ans = 1e+8;
    VI best_p(p.begin(), p.end());

    do {
      double g = 0, gt = 0;
      for (int i = 0; i < N; i++) {
        g += (i + 1) * W[p[i]];
        gt += W[p[i]];
      }
      g /= gt;

      bool flg = true;
      for (int i = N - 1; i >= 0; i--) {
        int sum = 0;
        for (int j = i + 1; j < N; j++) {
          sum += W[p[j]];
        }
        flg &= sum <= S[p[i]];
      }

      if (flg && g < ans + EPS) {
        ans = g;
        swap(best_p, p);
      }
    } while (next_permutation(p.begin(), p.end()));

    for (auto i : best_p) {
      cout << F[i] << endl;
    }
  }

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

#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<int> w, s, hist;
vector<string> name;
int n, tmpn, tmpm;
int used, ret[10];
string str;
double gmin = 1e+10;

inline double calc_g() {
  double p = 0;
  double q = 0;
  for (int i = 0; i < n; i++) {
    p += (i + 1) * w[hist[n - 1 - i]];
    q += w[hist[i]];
  }
  return p / q;
}

void solve(int num, int weight) {
  if (num == n) {
    double g = calc_g();
    if (gmin > g) {
      gmin = g;
      for (int i = 0; i < n; i++) {
        ret[i] = hist[i];
      }
    }
    return;
  }

  for (int i = 0; i < n; i++) {
    if ((used & (1 << i)) == 0) {
      if (s[i] >= weight) {
        // ツ鳴「ツ使ツ用ツづつゥツづつ重ツづ敖づ可妥渉つヲツづァツづェツつスツづァツ静渉づアツづづ敖づゥ
        used |= 1 << i;
        hist.push_back(i);
        solve(num + 1, weight + w[i]);
        hist.pop_back();
        used ^= 1 << i;
      }
    }
  }
}

int main(void) {
  while (cin >> n && n) {
    w.clear();
    s.clear();
    hist.clear();
    name.clear();
    memset(ret, 0, sizeof(ret));
    used = 0;
    gmin = 1e+10;
    for (int i = 0; i < n; i++) {
      cin >> str >> tmpn >> tmpm;
      name.push_back(str);
      w.push_back(tmpn);
      s.push_back(tmpm);
    }
    solve(0, 0);
    for (int i = 0; i < n; i++) {
      cout << name[ret[n - i - 1]] << endl;
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<int> w, s, hist, ret;
vector<string> name;
int n, tmpn, tmpm;
int used;
string str;
double gmin = 1e+10;

double calc_g() {
  double p = 0;
  double q = 0;
  for (int i = 0; i < n; i++) {
    p += (n - i - i) * hist[n - 1 - i];
    q += hist[i];
  }
  return p / q;
}

void solve(int num, int weight) {
  if (num == n) {
    double g = calc_g();
    if (gmin > g) {
      cout << g << endl;
      gmin = g;
      ret = hist;
    }
    return;
  }

  for (int i = 0; i < n; i++) {
    if ((used & (1 << i)) == 0) {
      if (s[i] >= weight) {
        // ツ鳴「ツ使ツ用ツづつゥツづつ重ツづ敖づ可妥渉つヲツづァツづェツつスツづァツ静渉づアツづづ敖づゥ
        used += 1 << i;
        hist.push_back(i);
        solve(num + 1, weight + w[i]);
        hist.pop_back();
        used -= 1 << i;
      }
    }
  }
}

int main(void) {
  while (cin >> n && n) {
    w.clear();
    s.clear();
    hist.clear();
    ret.clear();
    name.clear();
    used = 0;
    gmin = 1e+10;
    for (int i = 0; i < n; i++) {
      cin >> str >> tmpn >> tmpm;
      name.push_back(str);
      w.push_back(tmpn);
      s.push_back(tmpm);
    }
    solve(0, 0);
    for (int i = 0; i < n; i++) {
      cout << name[ret[n - i - 1]] << endl;
    }
  }
}
Problem p00170 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MAXN = 10;
const double inf = 1e10;

int n;
string f[MAXN];
int w[MAXN], s[MAXN];
double minG;
vector<int> t, ans, used;

void rec(int k, int sumww, int sumw) {
  if (k == -1) {
    double G = (double)sumww / (double)sumw;
    if (G < minG) {
      ans = t;
      minG = G;
    }
    return;
  }
  for (int i = 0; i < n; ++i) {
    t[k] = i;
    if (used[t[k]])
      continue;
    if (s[t[k]] >= sumw) {
      used[t[k]] = true;
      rec(k - 1, sumww + (k + 1) * w[t[k]], sumw + w[t[k]]);
      used[t[k]] = false;
    }
  }
}

int main() {
  for (; cin >> n, n;) {
    for (int i = 0; i < n; ++i) {
      cin >> f[i] >> w[i] >> s[i];
    }
    minG = inf;
    t = used = vector<int>(n);
    rec(n - 1, 0, 0);
    for (int i = 0; i < n; ++i) {
      cout << f[ans[i]] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

const double inf = 1e10;

int main() {
  for (int n; cin >> n, n;) {
    string f[n];
    int w[n], s[n];
    for (int i = 0; i < n; ++i) {
      cin >> f[i] >> w[i] >> s[i];
    }
    vector<int> t(n), ans;
    for (int i = 0; i < n; ++i)
      t[i] = i;
    double minG = inf;
    do {
      try {
        for (int i = n - 1, sumw = 0; i >= 0; --i) {
          if (s[t[i]] >= sumw)
            ;
          else
            throw 0;
          sumw += w[t[i]];
        }
        double G = 0;
        int a = 0, b = 0;
        for (int i = 0; i < n; ++i) {
          a += (i + 1) * w[t[i]];
          b += w[t[i]];
        }
        G = (double)a / (double)b;
        if (G < minG) {
          ans = t;
          minG = G;
        }
      } catch (...) {
      }
    } while (next_permutation(t.begin(), t.end()));

    for (int i = 0; i < n; ++i) {
      cout << f[ans[i]] << endl;
    }
  }
  return 0;
}
Problem p00170 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int n;
bool use[10];
int w[10], s[10];
vector<int> tmp, ans;
int maximam, total;

void rec(int pos) {
  if (pos == n) {
    int g;
    g = 0;
    for (int i = 0; i < n; i++)
      g += (i + 1) * w[tmp[i]];
    if (maximam < g) {
      maximam = g;
      ans = tmp;
    }
    return;
  }

  for (int i = 0; i < n; i++) {
    if (!use[i]) {
      if (s[i] >= total) {
        use[i] = true;
        total += w[i];
        tmp.push_back(i);
        rec(pos + 1);
        tmp.pop_back();
        use[i] = false;
        total -= w[i];
      }
    }
  }
}

int main() {
  string f[10];

  while (1) {
    cin >> n;
    if (!n)
      break;

    for (int i = 0; i < n; i++) {
      cin >> f[i] >> w[i] >> s[i];
      use[i] = false;
    }

    total = 0;
    ans.clear();
    tmp.clear();
    maximam = 0;

    rec(0);

    for (int i = ans.size() - 1; i >= 0; i--)
      cout << f[ans[i]] << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int n;
bool use[10];
int w[10], s[10];
vector<int> tmp, ans;
int maximam;

void rec(int pos) {
  if (pos == n) {
    int weight, g;
    bool f;
    weight = 0;
    f = true;
    for (int i = 0; i < tmp.size(); i++) {
      if (s[tmp[i]] < weight) {
        f = false;
        break;
      }
      weight += w[tmp[i]];
    }
    if (!f)
      return;
    g = 0;
    for (int i = 0; i < n; i++)
      g += (i + 1) * w[tmp[i]];
    if (maximam < g) {
      maximam = g;
      ans = tmp;
    }
    return;
  }

  for (int i = 0; i < n; i++) {
    if (!use[i]) {
      use[i] = true;
      tmp.push_back(i);
      rec(pos + 1);
      tmp.pop_back();
      use[i] = false;
    }
  }
}

int main() {
  string f[10];

  while (1) {
    cin >> n;
    if (!n)
      break;

    for (int i = 0; i < n; i++) {
      cin >> f[i] >> w[i] >> s[i];
      use[i] = false;
    }

    ans.clear();
    tmp.clear();
    maximam = 0;
    rec(0);

    for (int i = ans.size() - 1; i >= 0; i--)
      cout << f[ans[i]] << endl;
  }
}
Problem p00170 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n, w[1000], s[1000];
string S[1000];
vector<int> b;
int maxn;
int main() {
  while (true) {
    cin >> n;
    b.clear();
    maxn = 1 << 30;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> S[i] >> w[i] >> s[i];
    }
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++)
      a[i] = i;
    do {
      int sum2 = 0;
      for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = i + 1; j < n; j++) {
          sum += w[a[j]];
        }
        if (sum > s[a[i]])
          goto E;
      }
      for (int i = 0; i < n; i++) {
        sum2 += i * w[a[i]];
      }
      if (maxn > sum2) {
        b = a;
        maxn = sum2;
      }
    E:;
    } while (next_permutation(a.begin(), a.end()));
    for (int i = 0; i < n; i++) {
      cout << S[b[i]] << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n, w[1000], s[1000];
string S[1000];
vector<int> b;
int maxn;
int main() {
  while (true) {
    cin >> n;
    b.clear();
    maxn = 1 << 30;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> S[i] >> w[i] >> s[i];
    }
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++)
      a[i] = i;
    do {
      int sum2 = 0;
      for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = i + 1; j < n; j++) {
          sum += w[a[j]];
        }
        if (sum > s[a[i]])
          goto E;
      }
      for (int i = 0; i < n; i++) {
        sum2 += i * w[a[i]];
        maxn = sum2;
      }
      if (maxn > sum2)
        b = a;
    E:;
    } while (next_permutation(a.begin(), a.end()));
    for (int i = 0; i < n; i++) {
      cout << S[b[i]] << endl;
    }
  }
  return 0;
}
Problem p00173 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int a, s, d, f[10], h[10], i, j;
  char g[16][10];
  for (i = 1; i <= 9; i++) {
    scanf("%s %d %d", g[i], &s, &d);
    f[i] = s * 200 + d * 300;
    h[i] = s + d;
    printf("%s %d %d\\n", g[i], h[i], f[i]);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
int main(void) {
  char a;
  int s, z, i, f, g;
  while (scanf("%s %d %d", &a, &s, &z) != EOF) {
    f = s + z;
    g = (s * 200) + (z * 300);
    printf("%c %d %d\\n", a, f, g);
    s = 0;
    z = 0;
    f = 0;
    g = 0;
  }
  return 0;
}
Problem p00173 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
int main(void) {
  char name[16];
  int am, pm;
  while (scanf("%s %d %d", &name, &am, &pm) != EOF) {
    cout << name << " " << am + pm << " " << am * 200 + pm * 300 << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main(void) {
  string name;
  int am, pm;
  while (1) {
    cin >> name >> am >> pm;
    cout << name << " " << am + pm << " " << am * 200 + pm * 300 << "\\n";
  }
}
Problem p00173 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  char n[32];
  int m, a;
  for (int i = 0; i < 9; i++) {
    scanf("%s%d%d", n, &m, &a);
    printf("%s %d %d\\n", n, m + a, m * 200 + a * 300);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>

int main() {
  char n[32];
  int m, a;
  for (int i = 0; i < 9; i++) {
    scanf("%s%d%d", n, &m, &a);
    printf("%s %d %d\\n", m + a, m * 200 + a * 300);
  }
  return 0;
}