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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> pii;

int main() {
  int n, m, p, x;
  int num[105] = {};
  int i;

  while (1) {
    cin >> n >> m >> p;
    if (n == 0 && m == 0 && p == 0)
      break;
    ll sum = 0LL;
    rep(i, n) {
      cin >> x;
      num[i + 1] = x;
      sum += x;
    }
    sum = sum * (100 - p);
    if (num[m])
      cout << sum / num[m] << endl;
    else
      cout << "0" << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> pii;

int main() {
  int n, m, p, x;
  int num[105] = {};
  int i;

  while (1) {
    cin >> n >> m >> p;
    if (n == 0 && m == 0 && p == 0)
      break;
    ll sum = 0LL;
    rep(i, n) {
      cin >> x;
      num[x]++;
      sum += x;
    }
    sum = sum * (100 - p);
    if (num[m])
      cout << sum / num[m] << endl;
    else
      cout << "0" << endl;
  }
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  int N, M, P;
  int sum, ans;
  int X[1001];

  while (true) {
    cin >> N >> M >> P;
    if (!N && !M && !P)
      break;

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

    P = 100 - P;

    if (X[M - 1] == 0)
      ans = 0;
    else
      ans = sum * P / X[M - 1];

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

Error: 0

Fixed submission:

#include <cstdio>
using namespace std;

int main(void) {
  int N, M, P;
  while (scanf("%d %d %d", &N, &M, &P) != EOF && (N != 0 && M != 0 && P != 0)) {
    int sum = 0;
    int *X = new int[N];
    for (int i = 0; i < N; i++) {
      scanf("%d", X + i);
      sum += X[i];
    }
    if (X[M] == 0) {
      printf("%d\\n", 0);
    } else {
      printf("%d\\n", (int)((sum * (100 - P)) / X[M - 1]));
    }
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, m, p;
  while (cin >> n >> m >> p && n) {
    int sum = 0;
    int dl[n];
    rep(i, n) {
      cin >> dl[i];
      sum += dl[i];
    }
    if (dl[m - 1] == 0) {
      cout << 0 << endl;
    } else {
      cout << sum * (100 - p) / dl[m - 1] << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n, m, p;
  while (cin >> n >> m >> p && n && m && p) {
    int sum = 0;
    vector<int> dl(m);
    rep(i, n) {
      cin >> dl[i];
      sum += dl[i];
    }
    if (dl[m - 1] == 0) {
      cout << 0 << endl;
    } else {
      cout << sum * (100 - p) / dl[m - 1] << endl;
    }
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stack>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rep_to(a, i, x) for (int i = a; i < x; i++)

using namespace std;

int main() {
  int N, M, P;
  while (cin >> N >> M >> P && N) {
    int x[100000] = {};
    double sum = 0;

    rep(i, N) {
      cin >> x[i];
      sum += x[i] * 100;
    }

    if (x[M - 1] != 0)
      cout << floor(sum / x[M - 1] * (100 - P) / 100) << endl;
    else
      cout << 0 << endl;
  }
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stack>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rep_to(a, i, x) for (int i = a; i < x; i++)

using namespace std;

int main() {
  int N, M, P;
  while (cin >> N >> M >> P && N) {
    int x[10000] = {};
    int sum = 0;

    rep(i, N) {
      cin >> x[i];
      sum += x[i] * 100;
    }

    if (x[M] != 0)
      cout << sum / x[M - 1] * (100 - P) / 100 << endl;
    else
      cout << 0 << endl;
  }
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)

int main() {
  while (1) {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == 0 && m == 0 && p == 0)
      break;
    int count = 0, ans, a;
    lp(i, n) {
      cin >> a;
      count += a;
      if (i == m - 1)
        ans = a;
    }
    count *= 100;
    count *= (100 - p);
    if (ans != 0)
      cout << count / ans / 100 << endl;
    else
      cout << "0" << endl;
  }
  return 0;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)

int main() {
  while (1) {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == 0 && m == 0 && p == 0)
      break;
    int count = 0, ans, a;
    lp(i, n) {
      cin >> a;
      count += a;
      if (i == m - 1)
        ans = a;
    }
    count *= 100;
    count *= (100 - p);
    cout << count / a / 100 << endl;
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 1; i <= n; i++)

int main() {
  while (true) {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == 0 && m == 0 && p == 0)
      break;
    int x;
    int hito = 0, sum = 0;
    ;

    rep(i, n) {
      cin >> x;
      sum += x;
      if (i == m) {
        hito = x;
      }
    }
    if (hito == 0) {
      cout << 0 << '\\n';
    } else {
      cout << sum * (100 - p) / hito << '\\n';
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 1; i <= n; i++)

int main() {
  while (true) {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == 0 && m == 0 && p == 0)
      break;
    int x;
    int hito = 0, sum = 0;

    rep(i, n) {
      cin >> x;
      sum += x;
      if (i == m) {
        hito = x;
      }
      if (hito == 0) {
        cout << 0 << '\\n';
      } else {
        cout << hito * (100 - p) / x << '\\n';
      }
    }
  }
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m, p;
  while (cin >> n >> m >> p, n || m || p) {
    int ch[100], mm = 0, ans;
    for (int i = 1; i <= n; i++) {
      cin >> ch[i];
      mm += ch[i];
    }
    mm *= 100;
    if (ch[m] == 0)
      cout << ch[m] << endl;
    else {
      mm = mm * (100 - p) / 100;
      ans = mm / ch[m];
      cout << ans << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long ll;

int main(void) {
  int N, M, P;
  while (cin >> N >> M >> P && N && M && P) {
    int X[M + 1], sum = 0;
    ;
    for (int i = 1; i <= N; i++) {
      cin >> X[i];
      sum += X[i];
    }
    if (X[M] == 0) {
      cout << 0 << endl;
      continue;
    }
    cout << (int)(100 * sum * (1 - 1.0 * P / 100) / X[M]) << endl;
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m, h;
  int data[110];
  while (1) {
    cin >> n >> m >> h;
    if (n == 0 && m == 0 && h == 0)
      break;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> data[i];
      sum += data[i];
    }
    if (data[m - 1] == 0) {
      cout << "0" << endl;
      continue;
    }
    sum = sum * 100;
    sum = sum * (100 - h);
    sum = sum / 100;
    cout << sum / data[m - 1] << endl;
  }
}

Error: -8

Fixed submission:

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

int main() {
  int n, m, h;
  int data[110];
  while (1) {
    cin >> n >> m >> h;
    if (n == 0 && m == 0 && h == 0)
      break;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> data[i];
      sum += data[i];
    }
    sum = sum * 100;
    sum = sum * h;
    sum = sum / 100;
    cout << sum / data[m - 1] << endl;
  }
}
Problem p01143 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, p;

  while (cin >> n >> m >> p && (n || m || p)) {
    int sum = 0;
    int maisu = 0;
    int winner = -1;
    for (int i = 0; i < n; i++) {
      cin >> maisu;
      sum += maisu;
      if (i + 1 == m)
        winner = maisu;
    }

    if (winner != 0) {
      cout << (sum * (100 - p)) / winner << endl;
    } else {
      cout << 0 << endl;
    }
    winner = -1;
    maisu = 0;
    sum = 0;
  }

  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, p;
  int j = 0;
  vector<long long> ans(10000000);

  while (1) {
    cin >> n >> m >> p;
    if (n == 0 && m == 0 && p == 0)
      break;
    long long sum = 0;

    vector<int> x(n, 0);
    for (int i = 0; i < n; i++) {
      cin >> x[i];
      sum += x[i];
    }

    if (x[m - 1] != 0) {
      ans[j] = (sum * 100 / x[m - 1]) * (100 - p) / 100;
    } else {
      ans[j] = 0;
    }
    j++;
  }

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

#include <iostream>
using namespace std;

int main() {
  int N, M, P;

  while (1) {
    cin >> N >> M >> P;
    if ((N == 0) && (M == 0) && (P == 0)) {
      break;
    }

    double A[N];
    double sum = 0;
    double num = 0;
    double money;
    for (int i = 1; i <= N; i++) {
      cin >> A[i];
      sum += A[i] * 100;
      if (i == M) {
        num = A[i];
      }
    }

    money = (sum * (100 - P) / 100) / num;
    // cout << M << " " << num << " " << sum << " " << money << " " << P <<
    // endl;

    if (num == 0) {
      cout << 0 << endl;
    } else if (num != 0) {
      cout << (int)money << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N, M, P;

  while (1) {
    cin >> N >> M >> P;

    double A[N];
    double sum = 0;
    double num = 0;
    double money;
    for (int i = 1; i <= N; i++) {
      cin >> A[i];
      sum += A[i] * 100;
      if (i == M) {
        num = A[i];
      }
    }

    money = (sum * (100 - P) / 100) / num;
    // cout << M << " " << num << " " << sum << " " << money << " " << P <<
    // endl;

    if (num == 0) {
      cout << 0 << endl;
    } else if (num != 0) {
      cout << (int)money << endl;
    }
  }
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)

using namespace std;

int main() {
  int n, m, p, x[101];
  while (scanf("%d%d%d", &n, &m, &p) && (n || m || p)) {
    int sum = 0;
    rep(i, n) {
      scanf("%d", x + i);
      sum += x[i];
    }

    if (x[m - 1] != 0)
      printf("%d\\n", sum * (100 - p) / x[m - 1]);
    else
      printf("0\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)

using namespace std;

int main() {
  int n, m, p, x[101], sum;
  while (scanf("%d%d%d", &n, &m, &p) && (n || m || p)) {
    sum = 0;
    rep(i, n) {
      scanf("%d", x + i);
      sum += x[i];
    }

    if (x[m] != 0)
      printf("%d\\n", sum * (100 - p) / x[m - 1]);
    else
      printf("0\\n");
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {

  int N, M, P;
  while (1) {

    scanf("%d %d %d", &N, &M, &P);
    if (N == 0 && M == 0 && P == 0)
      break;

    int x, s = 0, y = 0;
    for (int i = 0; i < N; i++) {
      scanf("%d", &x);
      s += x;
      if (M == i + 1)
        y = x;
    }
    if (y != 0) {
      double t = 100 * s;
      t = t / y * (100 - P) / 100;
      printf("%d\\n", (int)t);
    } else
      printf("0\\n");
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {

  int N, M, P;
  while (1) {

    scanf("%d %d %d", &N, &M, &P);
    if (N == 0 && M == 0 && P == 0)
      break;

    int x, s = 0, y = 0;
    for (int i = 0; i < N; i++) {
      scanf("%d", &x);
      s += x;
      if (M == i - 1)
        y = x;
    }

    printf("%d\\n", (y / s * (100 - P) / 100));
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
using namespace std;

int main() {
  int N, M, P;
  while (cin >> N >> M >> P, N) {
    int a, sum = 0, win;
    REP(i, 0, N) {
      cin >> a;
      if (i + 1 == M)
        win = a;
      sum += a * 100;
    }
    sum *= 100 - P;
    sum /= 100;
    if (win == 0)
      cout << "0" << endl;
    else
      cout << sum / win << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n, N) for (int i = n; i < N; i++)
#define p(S) cout << S << endl
using namespace std;

int main() {
  int N, M, P;
  while (cin >> N >> M >> P, N) {
    int a, sum = 0, win;
    REP(i, 0, N) {
      cin >> a;
      if (i == M)
        win = a;
      sum += a * 100;
    }
    sum *= 100 - P;
    sum /= 100;
    cout << sum / win << endl;
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m, p, x[1000];
  while (1) {
    cin >> n >> m >> p;

    int sum = 0;

    if (n == 0 && m == 0 && p == 0)
      break;

    p = 100 - p;

    for (int i = 0; i < n; i++) {
      cin >> x[i];
      sum += x[i];
    }
    p *= sum;

    if (x[m - 1] == 0)
      p = 0;
    else
      p = p / x[m - 1];

    cout << p << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, p, x[1000];
  while (1) {
    cin >> n >> m >> p;

    int sum = 0;

    if (n == 0 && m == 0 && p == 0)
      break;

    p = 100 - p;

    for (int i = 0; i < n; i++) {
      cin >> x[i];
      sum += x[i];
    }
    p *= sum;
    p = p / x[m - 1];

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

#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
  int n, m;
  double p;
  while (cin >> n >> m >> p && n && m) {
    // p /= 100;
    vector<int> x;
    int cnt = 0, y;
    for (int i = 0; i < n; i++) {
      cin >> y;
      x.push_back(y);
    }
    double money = 100 * accumulate(x.begin(), x.end(), 0);
    money = money * (100 - p);
    if (x[m - 1] == 0)
      cout << 0 << endl;
    else
      cout << (int)(money / (double)x[m - 1] / 100.0) << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
  int n, m;
  double p;
  while (cin >> n >> m >> p) {
    p /= 100;
    vector<int> x;
    int cnt = 0, y;
    for (int i = 0; i < n; i++) {
      cin >> y;
      x.push_back(y);
    }
    double money = 100 * accumulate(x.begin(), x.end(), 0);
    money = money * (1.0 - p);
    if (x[m - 1] == 0)
      cout << 0 << endl;
    else
      cout << (int)(money / x[m - 1]) << endl;
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, h, sum, a[111];
  while (1) {
    cin >> n >> m >> h;
    if (n == 0 && m == 0 && h == 0)
      break;
    sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    if (a[m - 1] == 0) {
      cout << "0" << endl;
      continue;
    }
    sum = sum * 100 * (100 - h) / 100;
    cout << sum / a[m - 1] << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, c, i, d, e, sum;
  while (1) {
    sum = 0;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0)
      break;
    if (b == 0)
      cout << 0;
    else {
      for (i = 0; i < a; i++) {
        cin >> d;
        sum += d;
        if (i == b - 1)
          e = d;
      }

      if (c == 100)
        cout << 0;
      else if (c == 0)
        cout << sum * 100 / e;
      else
        cout << (sum * 100 - sum * c) / e;
    }
    cout << endl;
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, p;
  while (1) {
    cin >> n >> m >> p;
    if (n == 0 && m == 0) {
      if (p == 0)
        break;
    }
    int x[n + 1], sum = 0;
    for (int i = 1; i <= n; i++) {
      cin >> x[i];
      sum += x[i];
    }
    sum *= 100;
    if (x[m] == 0) {
      cout << 0 << endl;
    } else {
      sum = sum * 100;
      sum = sum - (sum / 100 * p);
      sum = sum / 100;
      sum = sum / x[m];
      cout << sum << endl;
    }
  }
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, p;
  while (1) {
    cin >> n >> m >> p;
    if (n == 0 && m == 0) {
      if (p == 0)
        break;
    }
    int x[n + 1], sum = 0;
    for (int i = 1; i <= n; i++) {
      cin >> x[i];
      sum += x[i];
    }
    sum *= 100;
    if (x[m] == 0) {
      cout << 0 << endl;
    }
    sum = sum * 100;
    sum = sum - (sum / 100 * p);
    sum = sum / 100;
    sum = sum / x[m];
    cout << sum << endl;
  }
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#define INF 100000000
using namespace std;

int main() {
  int n, m, p;

  while (cin >> n >> m >> p, n + m + p) {

    int sum = 0;
    int a[101] = {0};

    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    if (a[m - 1] == 0) {
      cout << 0 << endl;
      continue;
    }
    sum = sum * (100 - p);
    int ans = sum / a[m - 1];
    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#define INF 100000000
using namespace std;

int main() {
  int n, m;
  double p;
N:;
  while (cin >> n >> m >> p, n + m + p) {
    double sum = 0;
    int a[101] = {0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i == m - 1 && a[i] == 0) {
        cout << 0 << endl;
        goto N;
      }
      sum += a[i];
    }
    double M = sum;
    sum = sum * (1 - (p / 100));
    printf("%d\\n", (int)(100 * (sum / a[m - 1])));
  }
  return 0;
}
Problem p01143 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int n, m, p;
  int num[101];
  while (cin >> n >> m >> p, n | m | p) {
    int total = 0;
    for (int i = 1; i <= n; i++) {
      cin >> num[i];
      total += num[i] * (100 - p);
    }
    if (!num[m]) {
      cout << 0 << endl;
      continue;
    }
    cout << (total / num[m]) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m, p;
  int num[101];
  while (cin >> n >> m >> p, n | m | p) {
    int total = 0;
    for (int i = 1; i <= n; i++) {
      cin >> num[i];
      total += num[i] * (100 - p);
    }
    if (!num[n]) {
      cout << 0 << endl;
      continue;
    }
    cout << (total / num[m]) << endl;
  }
  return 0;
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
int N, D, P;
long long int M, S, SD;
pair<int, int> DP[10010];
int main() {
  while (cin >> N >> M && N > 0) {
    S = 0;
    SD = 0;
    for (int i = 0; i < N; i++) {
      cin >> D >> P;
      DP[i] = make_pair(P, D);
      S = S + D * P;
      SD = SD + D;
    }
    if (SD < M) {
      cout << "0" << endl;
    } else {
      sort(DP, DP + N);
      for (int j = 0; j < N; j++) {
        if (M > 0) {
          if (M > DP[N - 1 - j].second) {
            S = S - DP[N - 1 - j].first * DP[N - 1 - j].second;
            M = M - DP[N - 1 - j].second;
          } else {
            S = S - M * DP[N - 1 - j].first;
            M = 0;
          }
        }
      }
      cout << S << endl;
    }
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
int N, D, P;
long long int M, S, SD;
pair<int, int> DP[10010];
int main() {
  while (cin >> N >> M && N > 0) {
    for (int i = 0; i < N; i++) {
      cin >> D >> P;
      DP[i] = make_pair(P, D);
      S = S + D * P;
      SD = SD + D;
    }
    sort(DP, DP + N);
    int j = 0;
    if (SD > M) {
      while (M > 0) {
        if (M > DP[N - 1 - j].second) {
          S = S - DP[N - 1 - j].first * DP[N - 1 - j].second;
          M = M - DP[N - 1 - j].second;
          j = j + 1;
        } else {
          S = S - M * DP[N - 1 - j].first;
          M = 0;
        }
      }
      cout << S << endl;
    } else
      cout << "0" << endl;
  }
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

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

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

using namespace std;

bool cmp(pair<int, int> &x, pair<int, int> &y) { return x.second > y.second; }

int main(void) {
  int n, m;
  while (cin >> n >> m, n > 0) {
    int j = 0, ans = 0;
    vector<pair<int, int>> dp(n);
    rep(i, n) {
      int d, p;
      cin >> d >> p;
      dp[i] = make_pair(d, p);
    }
    sort(dp.begin(), dp.end(), cmp);
    while (m > 0) {
      if (m > dp[j].first) {
        m -= dp[j].first;
        dp[j].first = 0;
        j++;
        if (j == n)
          break;
      } else {
        dp[j].first -= m;
        m = 0;
      }
    }
    rep(i, n) { ans += dp[i].first * dp[i].second; }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

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

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

using namespace std;

bool cmp(pair<int, int> &x, pair<int, int> &y) { return x.second > y.second; }

int main(void) {
  int n, m;
  while (cin >> n >> m, n > 0) {
    int j = 0, ans = 0;
    vector<pair<int, int>> dp(n);
    rep(i, n) {
      int d, p;
      cin >> d >> p;
      dp[i] = make_pair(d, p);
    }
    sort(dp.begin(), dp.end(), cmp);
    while (m > 0) {
      if (m > dp[j].first) {
        m -= dp[j].first;
        dp[j].first = 0;
        j++;
      } else {
        dp[j].first -= m;
        m = 0;
      }
    }
    rep(i, n) { ans += dp[i].first * dp[i].second; }
    cout << ans << endl;
  }
  return 0;
}