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

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

#define REP(i, n, m) for (int i = n; i < m; i++)
#define rep(i, n) REP(i, 0, n)

class State {
public:
  int cost, x, y;

  State(int _cost, int _x, int _y) {
    cost = _cost;
    x = _x;
    y = _y;
  }
};

int dx[] = {-2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2};
int dy[] = {-1, 0, 1, -2, 2, -2, 2, -2, 2, -1, 0, 1};

int main(void) {
  int sx, sy;

  while (cin >> sx >> sy && (sx || sy)) {
    int n;
    cin >> n;

    bool t[10][10][10];
    memset(t, 0, sizeof(t));
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      REP(j, -1, 2) REP(k, -1, 2) {
        int nx = x + j;
        int ny = y + k;
        if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10)
          t[i][ny][nx] = true;
      }
    }

    queue<State> open;
    open.push(State(-1, sx, sy));
    bool ans = false;

    if (n == 0) {
      cout << "NA\\n";
      continue;
    }

    while (!open.empty()) {
      State st = open.front();
      open.pop();

      if (st.cost == n - 1) {
        ans = true;
        break;
      }

      rep(i, 12) {
        int nx = st.x + dx[i];
        int ny = st.y + dy[i];
        int nc = st.cost + 1;

        if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10 && t[nc][ny][nx]) {
          open.push(State(nc, nx, ny));
          t[nc][ny][nx] = false;
        }
      }
    }
    cout << (ans ? "OK" : "NA") << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

#define REP(i, n, m) for (int i = n; i < m; i++)
#define rep(i, n) REP(i, 0, n)

class State {
public:
  int x, y;
  int cost;

  State(int tx, int ty, int tcost) {
    x = tx;
    y = ty;
    cost = tcost;
  }

  bool operator==(const State st) const {
    return x == st.x && y == st.y && cost == st.cost;
  }
};

queue<State> open;

int n;
char t[10][10][10];
int sdx[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int sdy[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dx[] = {-2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2};
int dy[] = {1, 0, -1, -2, 2, -2, 2, -2, 2, -1, 0, 1};

bool contains(State st) {
  int size = open.size();
  bool res = false;
  rep(i, size) {
    if (open.front() == st)
      res = true;
    open.push(open.front());
    open.pop();
  }
  return res;
}

void nexts(State st) {
  rep(i, 12) {
    int nx = st.x + dx[i];
    int ny = st.y + dy[i];
    int ncost = (st.cost + 1) % n;

    if (nx >= 0 && nx < 10 && ny >= 0 && ny < 10 && t[ny][nx][ncost]) {
      State nst(nx, ny, ncost);
      if (!contains(nst))
        open.push(nst);
    }
  }
}

int main(void) {
  int x, y, sx, sy;

  while (cin >> sx >> sy && (sx || sy)) {
    memset(t, 0, sizeof(t));

    cin >> n;
    rep(i, n) {
      cin >> x >> y;
      rep(j, 9) t[y + sdy[j]][x + sdx[j]][i] = 1;
    }

    int count = 0;

    while (!open.empty())
      open.pop();
    State start(sx, sy, -1);
    nexts(start);

    for (int i = 0; !open.empty() && i < 1000; i++) {
      State st = open.front();
      open.pop();
      nexts(st);
    }

    cout << (open.empty() ? "NA" : "OK") << endl;
  }

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

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  double t1, t2;
  while (scanf("%lf %lf\\n", &t1, &t2) != EOF) {
    const double bound_1[100] = {35.5, 37.5, 40, 43, 50, 55, 70};
    const double bound_2[100] = {71, 77, 83, 89, 105, 116, 148};
    const string c[100] = {"AAA", "AA", "A", "B", "C", "D", "E"};
    int i = 0, num;
    while (1) {
      if (t1 < bound_1[i] && t2 < bound_2[i]) {
        cout << c[i] << endl;
        break;
      }
      if (i > 7) {
        printf("NA\\n");
        break;
      }
      i++;
    }
    /* for( int i = 0; i < 7; i++ )
    {
        if( t1 > bound_1[i] )
        {
            num1 = i;
        }
        if( t2 > bound_2[i] )
        {
            num2 = i;
        }
    } */
  }
  return 0;
}


Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  double t1, t2;
  while (scanf("%lf %lf\\n", &t1, &t2) != EOF) {
    printf("%lf %lf\\n", t1, t2);
    const double bound_1[7] = {35.5, 37.5, 40, 43, 50, 55, 70};
    const double bound_2[7] = {71, 77, 83, 89, 105, 116, 148};
    const string c[7] = {"AAA", "AA", "A", "B", "C", "D", "E"};
    int i = 0, num;
    while (1) {
      if (t1 < bound_1[i] && t2 < bound_2[i]) {
        cout << c[i] << endl;
        break;
      }
      if (i > 7) {
        printf("NA\\n");
        break;
      }
      i++;
    }
    /* for( int i = 0; i < 7; i++ )
    {
        if( t1 > bound_1[i] )
        {
            num1 = i;
        }
        if( t2 > bound_2[i] )
        {
            num2 = i;
        }
    } */
  }
  return 0;
}
Problem p00123 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  double a, b;
  while (scanf("%lf%lf", &a, &b) != EOF) {
    if (a < 35.5 && b < 71)
      printf("AAA\\n");
    else if (a < 37.5 && b < 77)
      printf("AA\\n");
    else if (a < 40 && b < 83)
      printf("A\\n");
    else if (a < 43 && b < 89)
      printf("B\\n");
    else if (a < 50 && b < 105)
      printf("C\\n");
    else if (a < 55 && b < 116)
      printf("D\\n");
    else if (a < 70 && b < 148)
      printf("E\\n");
    else
      printf("NA\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  double a, b;
  while (scanf("%lf%lf", &a, &b)) {
    if (a < 35.5 && b < 71)
      printf("AAA\\n");
    else if (a < 37.5 && b < 77)
      printf("AA\\n");
    else if (a < 40 && b < 83)
      printf("A\\n");
    else if (a < 43 && b < 89)
      printf("B\\n");
    else if (a < 50 && b < 105)
      printf("C\\n");
    else if (a < 55 && b < 116)
      printf("D\\n");
    else if (a < 70 && b < 148)
      printf("E\\n");
    else
      printf("NA\\n");
  }
  return 0;
}
Problem p00123 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  float a, b;
  while (scanf("%f %f", &a, &b) != EOF) {
    if (a < 35.5 && b < 71) {
      printf("AAA\\n");
    } else if (a < 37.5 && b < 77) {
      printf("AA\\n");
    } else if (a < 40 && b < 83) {
      printf("A\\n");
    } else if (a < 43 && b < 89) {
      printf("B\\n");
    } else if (a < 50 && b < 105) {
      printf("C\\n");
    } else if (a < 55 && b < 116) {
      printf("D\\n");
    } else if (a < 70 && b < 148) {
      printf("E\\n");
    } else {
      printf("NA\\n");
    }
    //	scanf("%d %d",&a,&b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    if (a > 35.5 && b > 71) {
      printf("AAA\\n");
    } else if (a > 37.5 && b > 77) {
      printf("AA\\n");
    } else if (a > 40 && b > 83) {
      printf("A\\n");
    } else if (a > 43 && b > 89) {
      printf("B\\n");
    } else if (a > 50 && b > 105) {
      printf("C\\n");
    } else if (a > 55 && b > 116) {
      printf("D\\n");
    } else if (a > 60 && b > 148) {
      printf("E\\n");
    } else {
      printf("NA\\n");
    }
    //	scanf("%d %d",&a,&b);
  }
  return 0;
}
Problem p00123 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  float hideo, ruio;
  while (scanf("%f %f", &hideo, &ruio) != EOF) {
    if (hideo < 35.50 && ruio < 71.00) {
      printf("AAA\\n");
    } else if (hideo < 37.50 && ruio < 77.00) {
      printf("AA\\n");
    } else if (hideo < 40.00 && ruio < 83.00) {
      printf("A\\n");
    } else if (hideo < 43.00 && ruio < 89.00) {
      printf("B\\n");
    } else if (hideo < 50.00 && ruio < 105.00) {
      printf("C\\n");
    } else if (hideo < 55.00 && ruio < 116.00) {
      printf("D\\n");
    } else if (hideo < 70.00 && ruio < 148.00) {
      printf("E\\n");
    } else {
      printf("NA\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  float hideo, ruio;
  while (scanf("%f %f", &hideo, &ruio)) {
    if (hideo < 35.50 && ruio < 71.00) {
      printf("AAA\\n");
    } else if (hideo < 37.50 && ruio < 77.00) {
      printf("AA\\n");
    } else if (hideo < 40.00 && ruio < 83.00) {
      printf("A\\n");
    } else if (hideo < 43.00 && ruio < 89.00) {
      printf("B\\n");
    } else if (hideo < 50.00 && ruio < 105.00) {
      printf("C\\n");
    } else if (hideo < 55.00 && ruio < 116.00) {
      printf("D\\n");
    } else if (hideo < 70.00 && ruio < 148.00) {
      printf("E\\n");
    } else {
      printf("NA\\n");
    }
  }
  return 0;
}
Problem p00123 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define INF 114514
using namespace std;

int main() {
  double fh, om;
  while (cin >> fh >> om) {
    if (fh < 35.5 && om < 71.0) {
      puts("AAA");
    } else if (fh < 37.5 && om < 77.0) {
      puts("AA");
    } else if (fh < 40.0 && om < 83.0) {
      puts("A");
    } else if (fh < 43.0 && om < 89.0) {
      puts("B");
    } else if (fh < 50.0 && om < 105.0) {
      puts("C");
    } else if (fh < 55.0 && om < 116.0) {
      puts("D");
    } else if (fh < 70.0 && om < 148.0) {
      puts("E");
    } else {
      puts("NA");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define INF 114514
using namespace std;

int main() {
  double fh, om;
  while (scanf("%lf %lf", &fh, &om)) {
    if (fh < 35.5 && om < 71.0) {
      puts("AAA");
    } else if (fh < 37.5 && om < 77.0) {
      puts("AA");
    } else if (fh < 40.0 && om < 83.0) {
      puts("A");
    } else if (fh < 43.0 && om < 89.0) {
      puts("B");
    } else if (fh < 50.0 && om < 105.0) {
      puts("C");
    } else if (fh < 55.0 && om < 116.0) {
      puts("D");
    } else if (fh < 70.0 && om < 148.0) {
      puts("E");
    } else {
      puts("NA");
    }
  }
  return 0;
}
Problem p00124 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
string a[10];
int p[10];
int main() {
  int n, b, z, c;
  bool first = true;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    if (!first)
      cout << endl;
    first = false;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b >> z >> c;
      p[i] = b * 3 + c * 1;
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (p[j] > p[j - 1]) {
          string tmps = a[j];
          a[j] = a[j - 1];
          a[j - 1] = tmps;
          int tmp = p[j];
          p[j] = p[j - 1];
          p[j - 1] = tmp;
        }
      }
    }
    for (int i = 0; i < n; i++)
      cout << a[i] << "," << p[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
string a[10];
int p[10];
int main() {
  int n, b, z, c;
  bool first = true;
  while (true) {
    cin >> n;
    if (!first)
      cout << endl;
    first = false;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b >> z >> c;
      p[i] = b * 3 + c * 1;
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (p[j] > p[j - 1]) {
          string tmps = a[j];
          a[j] = a[j - 1];
          a[j - 1] = tmps;
          int tmp = p[j];
          p[j] = p[j - 1];
          p[j - 1] = tmp;
        }
      }
    }
    for (int i = 0; i < n; i++)
      cout << a[i] << "," << p[i] << endl;
  }
  return 0;
}
Problem p00124 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>
int main(void) {
  char na[10][21], x[21];
  int n, w[10], l[10], d[10], a[10], i, j, y, flg;
  flg = 1;
  scanf("%d", &n);
  while (n != 0) {
    for (i = 0; i < n; i++) {
      scanf("%s %d %d %d", na[i], &w[i], &l[i], &d[i]);
      l[i] = w[i] * 3 + d[i];
      a[i] = i;
    }
    for (i = 0; i < n - 1; i++) {
      for (j = i + 1; j < n; j++) {
        if (l[i] < l[j] || l[i] == l[j] && a[i] > a[j]) {
          y = l[i];
          l[i] = l[j];
          l[j] = y;
          y = a[i];
          a[i] = a[j];
          a[j] = y;
          strcpy(x, na[i]);
          strcpy(na[i], na[j]);
          strcpy(na[j], x);
        }
      }
    }
    if (flg == 0)
      printf("\\n");
    for (i = 0; i < n; i++)
      printf("%s,%d\\n", na[i], l[i]);
    flg = 0;
    scanf(" %d", &n);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
int main(void) {
  char na[10][21], x[21];
  int n, w[10], l[10], d[10], i, j, y;
  while (scanf("%d", &n) != 0) {
    for (i = 0; i < n; i++) {
      scanf("%s %d %d %d", na[i], &w[i], &l[i], &d[i]);
      l[i] = w[i] * 3 + d[i];
    }
    for (i = 0; i < n - 1; i++) {
      for (j = i + 1; j < n; j++) {
        if (l[i] < l[j]) {
          y = l[i];
          l[i] = l[j];
          l[j] = y;
          strcpy(x, na[i]);
          strcpy(na[i], na[j]);
          strcpy(na[j], x);
        }
      }
    }
    for (i = 0; i < n; i++)
      printf("%s,%d\\n", na[i], l[i]);
  }
  return 0;
}
Problem p00124 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>
int main(void) {
  int n, i, j;
  int temp, data[10];
  char tn[11][21], temps[21];
  int k, m, h;
  scanf("%d", &n);
  while (n != 0) {
    for (j = 0; j < 10; j++) {
      data[j] = 0;
    }
    for (j = 0; j < n; j++) {
      scanf("%s %d %d %d", tn[j], &k, &m, &h);
      data[j] += k * 3;
      data[j] += h;
    }
    for (i = 0; i < n - 1; i++) {
      for (j = n - 1; j > i; j--) {
        if (data[j] > data[j - 1]) {
          temp = data[j];
          data[j] = data[j - 1];
          data[j - 1] = temp;
          strcpy(temps, tn[j]);
          strcpy(tn[j], tn[j - 1]);
          strcpy(tn[j - 1], temps);
        }
      }
    }
    for (j = 0; j < n; j++) {
      printf("%s,%d\\n", tn[j], data[j]);
    }
    scanf("%d", &n);
    if (n != 0) {
      printf("\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
int main(void) {
  int n, i, j;
  int temp, data[10];
  char tn[11][21], temps[21];
  int k, m, h;
  for (j = 0; j < 10; j++) {
    data[j] = 0;
  }
  while (scanf("%d", &n) != 0) {
    for (j = 0; j < n; j++) {
      scanf("%s %d %d %d", tn[j], &k, &m, &h);
      data[j] += k * 3;
      data[j] += h;
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        if (data[j] < data[j + 1]) {
          temp = data[j + 1];
          data[j + 1] = data[j];
          data[j] = temp;
          strcpy(temps, tn[j + 1]);
          strcpy(tn[j + 1], tn[j]);
          strcpy(tn[j], temps);
        }
      }
    }
    for (j = 0; j < n; j++) {
      printf("%s,%d\\n", tn[j], data[j]);
    }
    printf("\\n");
  }
  return 0;
}
Problem p00124 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int n, a, b, c, d;
pair<int, string> p[10];
int main() {
  while (scanf("%d", &n), n) {
    for (int i = 0; i < n; i++) {
      cin >> p[i].second >> a >> b >> c;
      p[i].first = i - a * 30 - c * 10;
    }
    sort(p, p + n);
    if (d++)
      printf("\\n");
    for (int i = 0; i < n; i++) {
      cout << p[i].second << ',' << (-p[i].first + 9) / 10 << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

int main() {
  int N, C = 0, X, Y, Z;

  while (true) {
    cin >> N;

    if (N == 0) {
      break;
    }

    if (C++) {
      cout << endl;
    }

    vector<pair<int, string>> R(N);

    for (int i = 0; i < N; i++) {
      cin >> R[i].second >> X >> Y >> Z;

      R[i].first = X * 3 + Z;
    }

    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; i++) {
        if (R[i].first < R[j].first) {
          swap(R[i], R[j]);
        }
      }
    }

    for (int i = 0; i < N; i++) {
      cout << R[i].second << ',' << R[i].first << endl;
    }
  }

  return 0;
}
Problem p00124 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
string s[1000000];
int a[1000000][3], score[1000000], cnt;
int n;
int main() {
  while (true) {
    cin >> n;
    if (!n) {
      break;
    }
    if (cnt) {
      cout << endl;
    }
    cnt++;
    for (int i = 0; i < n; i++) {
      cin >> s[i] >> a[i][0] >> a[i][1] >> a[i][2];
      score[i] = a[i][0] * 3 + a[i][2];
    }
    for (int j = 100000; j >= 0; j--) {
      for (int k = 0; k < n; k++) {
        if (score[k] == j) {
          cout << s[k] << ',' << score[k] << endl;
        }
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
string s[1000000];
int a[1000000][3], score[1000000];
int n;
int main() {
  while (true) {
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> s[i] >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
      score[i] = a[i][0] * 3 + a[i][1];
    }
    for (int j = 100000; j >= 0; j--) {
      for (int k = 0; k < n; k++) {
        if (score[k] == j) {
          cout << s[k] << ',' << score[k] << endl;
        }
      }
    }
  }
}
Problem p00124 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

typedef struct {
  int sum;
  char name[30];
} TEAM;

int main() {
  int n;
  int win, lose, drow;
  bool flg = false;
  TEAM team[10], tmp;

  while (1) {
    scanf("%d", &n);

    if (n == 0) {
      break;
    }

    for (int i = 0; i < n; i++) {
      scanf("%s %d %d %d", team[i].name, &win, &lose, &drow);
      team[i].sum = win * 3 + drow;
    }

    for (int i = 0; i < n; i++) {
      for (int j = n - 1; j > i; j--) {
        if (team[j].sum > team[j - 1].sum) {
          tmp = team[j - 1];
          team[j - 1] = team[j];
          team[j] = tmp;
        }
      }
    }

    if (flg == true) {
      cout << endl;
    }

    flg = true;

    for (int i = 0; i < n; i++) {
      cout << team[i].name << "," << team[i].sum << endl;
    }
  }

  return (0);
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

typedef struct {
  int sum;
  char name[20];
} TEAM;

int main() {
  int n;
  int win, lose, drow;
  bool flg = 0;
  TEAM team[10];

  while (1) {
    scanf("%d", &n);

    if (n == 0) {
      break;
    }

    if (flg == false) {
      flg = true;
    } else {
      cout << endl;
    }

    for (int i = 0; i < n; i++) {
      scanf("%s %d %d %d", team[i].name, &win, &lose, &drow);
      team[i].sum = win * 3 + drow;
    }

    char tmp[10];
    int n_tmp;

    for (int i = 0; i < n; i++) {
      for (int j = n - 1; j > i; j--) {
        if (team[j].sum > team[j - 1].sum) {
          strcpy(tmp, team[j - 1].name);
          n_tmp = team[j - 1].sum;

          strcpy(team[j - 1].name, team[j].name);
          team[j - 1].sum = team[j].sum;

          strcpy(team[j].name, tmp);
          team[j].sum = n_tmp;
        }
      }
    }

    for (int i = 0; i < n; i++) {
      cout << team[i].name << "," << team[i].sum << endl;
    }

    if (n != 0) {
      cout << endl;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int n, f = 0;
  while (cin >> n) {
    if (!n)
      break;
    if (f)
      cout << endl;
    else
      f = 1;
    vector<int> m;
    map<int, vector<string>> f;
    for (int i = 0; i < n; i++) {
      string name;
      cin >> name;
      int a, b, c;
      cin >> a >> b >> c;
      int p = -(a * 3 + c);
      if (count(m.begin(), m.end(), p) == 0)
        m.push_back(p);
      f[p].push_back(name);
    }
    sort(m.begin(), m.end());
    for (int i = 0; i < m.size(); i++) {
      for (int j = 0; j < f[m[i]].size(); j++) {
        cout << f[m[i]][j] << "," << -m[i] << endl;
      }
    }
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int n, f = 0;
  while (cin >> n) {
    if (!n)
      break;
    if (f)
      cout << endl;
    pair<int, string> m[n];
    for (int i = 0; i < n; i++) {
      cin >> m[i].second;
      int a, b, c;
      cin >> a >> b >> c;
      m[i].first = a * 3 + c * 1;
    }
    //        for (int i=0; i<n; i++) {
    //            for (int j=i+1; j<n; j++) {
    //                if (m[i].first<m[j].first) swap(m[i],m[j]);
    //            }
    //        }
    sort(m, m + n);
    for (int i = n; i >= 0; i--) {
      cout << m[i].second << "," << m[i].first << endl;
    }
    f++;
  }
}
Problem p00124 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct data {

  char name[21];
  int win;
  int lose;
  int draw;
  int score;
};

int main() {

  int teamamo;
  bool check = true;

  while (true) {

    cin >> teamamo;

    if (teamamo == 0)
      break;

    data teamdata[10];

    for (int i = 0; i < teamamo; i++)
      cin >> teamdata[i].name >> teamdata[i].win >> teamdata[i].lose >>
          teamdata[i].draw;

    for (int i = 0; i < teamamo; i++)
      teamdata[i].score = teamdata[i].win * 3 + teamdata[i].draw;

    for (int j = 0; j < teamamo - 1; j++) {
      for (int i = 0; i < teamamo - 1; i++) {

        if (teamdata[i].score < teamdata[i + 1].score) {

          data t = teamdata[i];
          teamdata[i] = teamdata[i + 1];
          teamdata[i + 1] = t;
        }
      }
    }

    if (check)
      check = false;
    else
      cout << endl;

    for (int i = 0; i < teamamo; i++)
      cout << teamdata[i].name << "," << teamdata[i].score << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

struct data {

  char name;
  int win;
  int lose;
  int draw;
  int score;
};

int main() {

  int teamamo;

  while (true) {

    cin >> teamamo;

    if (teamamo == 0)
      break;

    data teamdata[10];
    data comp;

    for (int i = 0; i < teamamo; i++)
      cin >> teamdata[i].name >> teamdata[i].win >> teamdata[i].lose >>
          teamdata[i].draw;

    for (int i = 0; i < teamamo; i++)
      teamdata[i].score = teamdata[i].win * 3 + teamdata[i].draw;

    for (int i = 0; i < teamamo - 1; i++) {

      if (teamdata[i].score < teamdata[i + 1].score) {

        char fout;
        fout = teamdata[i].name;
        teamdata[i].name = teamdata[i + 1].name;
        teamdata[i + 1].name = fout;

        int gout;
        gout = teamdata[i].score;
        teamdata[i].score = teamdata[i + 1].score;
        teamdata[i + 1].score = gout;
      }
    }

    for (int i = 0; i < teamamo; i++)
      cout << teamdata[i].name << ',' << teamdata[i].score << endl;
  }

  return 0;
}