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

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define For(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int n, m;
vector<pii> s(10010);

int main() {
  cin >> n >> m;
  while (n) {
    rep(i, n) {
      int d, p;
      cin >> d >> p;
      s[i] = pii(d, p);
    }
    sort(s.begin(), s.begin() + n,
         [](const pii &a, const pii &b) { return a.se > b.se; });
    rep(i, n) {
      if (m == 0)
        break;
      else if (s[i].fi <= m) {
        m -= s[i].fi;
        s[i] = pii(0, s[i].se);
      } else {
        s[i] = pii(s[i].fi - m, s[i].se);
        m = 0;
      }
    }
    int ans = 0;
    rep(i, n) ans += s[i].fi * s[i].se;
    cout << ans << endl;
    cin >> n >> m;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define For(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int n, m;
vector<pii> s(1010);

int main() {
  cin >> n >> m;
  while (n) {
    rep(i, n) {
      int d, p;
      cin >> d >> p;
      s[i] = pii(d, p);
    }
    sort(s.begin(), s.end(),
         [](const pii &a, const pii &b) { return a.se > b.se; });
    rep(i, n) {
      if (s[i].fi <= m) {
        m -= s[i].fi;
        s[i] = pii(0, s[i].se);
      } else {
        s[i] = pii(s[i].fi - m, s[i].se);
        m = 0;
      }
      if (!m)
        break;
    }
    int ans = 0;
    rep(i, n) ans += s[i].fi * s[i].se;
    cout << ans << endl;
    cin >> n >> m;
  }
}
Problem p01144 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, M, D, P;
  while (cin >> N >> M, N || M) {
    vector<int> dp(11);
    for (int i = 0; i < N; i++) {
      cin >> D >> P;
      dp[P] += D;
    }
    int res = 0;
    for (int i = 10; i >= 0; i--) {
      if (dp[i] < M) {
        M -= dp[i];
      } else {
        res += (dp[i] - M) * i;
        M = 0;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, M, D, P;
  while (cin >> N >> M, N || M) {
    priority_queue<int> pq;
    for (int i = 0; i < N; i++) {
      cin >> D >> P;
      for (int j = 0; j < D; j++)
        pq.push(P);
    }
    for (int i = 0; i < M; i++)
      pq.pop();
    int res = 0;
    while (!pq.empty()) {
      res += pq.top();
      pq.pop();
    }
    cout << res << endl;
  }
  return 0;
}
Problem p01144 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      return 0;
    } else {
      ll a, b;
      vp v;
      REP(i, n) {
        cin >> a >> b;
        v.push_back(make_pair(b, a));
      }
      sort(RALL(v));
      ans = 0;
      REP(i, n) {
        if (m >= v[i].second) {
          m -= v[i].second;
        } else {
          ans += (v[i].second - m) * v[i].first;
          m = 0;
        }
      }
      cout << ans << endl;
      v.clear();
    }
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main() {
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0) {
      return 0;
    } else {
      vi vans;
      ll a, b;
      vp v;
      REP(i, n) {
        cin >> a >> b;
        v.push_back(make_pair(b, a));
      }
      REP(i, n) {
        REP(j, v[i].second) { vans.push_back(v[i].first); }
      }
      sort(RALL(vans));
      sum = 0;
      FOR(i, m, vans.size()) { sum += vans[i]; }
      cout << sum << endl;
      vans.clear();
    }
  }
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

/*
Princess's Marriage
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019&lang=jp
20:10
*/

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

using std::cin;
using std::cout;
using std::min;
using std::pair;
using std::sort;
using std::vector;

#define INF 999999999;

long long int N, M;
vector<pair<int, int>> DaP; //(Dn, Pn)
long long int ans;

int main(void) {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  do {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++) {
      pair<int, int> inn;
      cin >> inn.first >> inn.second;
      ans += inn.first * inn.second;
      DaP.push_back(inn);
    }
    sort(DaP.begin(), DaP.end(), [](pair<int, int> a, pair<int, int> b) {
      return a.second > b.second;
    });
    int i = 0;
    while (M > 0) {
      long long int minus = min(M, (long long int)DaP[i].first);
      ans -= DaP[i].second * minus;
      M -= minus;
      i++;
      if (i == DaP.size())
        break;
    }
    cout << ans << "\\n";
    ans = 0;
    DaP.clear();

  } while (true);

  return 0;
}


Error: 0

Fixed submission:

/*
Princess's Marriage
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019&lang=jp
20:10
*/

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

using std::cin;
using std::cout;
using std::min;
using std::pair;
using std::sort;
using std::vector;

#define INF 999999999;

long long int N, M;
vector<pair<int, int>> DaP; //(Dn, Pn)
long long int ans;

int main(void) {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  do {
    cin >> N >> M;
    if (N == 0 && M == 0)
      break;
    for (int i = 0; i < N; i++) {
      pair<int, int> inn;
      cin >> inn.first >> inn.second;
      ans += inn.first * inn.second;
      DaP.push_back(inn);
    }
    sort(DaP.begin(), DaP.end(), [](pair<int, int> a, pair<int, int> b) {
      return a.second > b.second;
    });
    int i = 0;
    while (M > 0) {
      long long int minus = min(M, (long long int)DaP[i].first);
      ans -= DaP[i].second * minus;
      M -= minus;
      i++;
    }
    cout << ans << "\\n";
    ans = 0;
    DaP.clear();

  } while (true);

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

// C
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<pair<int, int>> t(0); // 危険度、距離
    t.resize(11001);
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b; // 距離、北市
      t[i] = (make_pair(b, a));
    }
    sort(t.begin(), t.end(), greater<pair<int, int>>());
    int iii = 0;
    while (m > 0) {
      bool f = 0;
      for (int j = 0; j < n; j++)
        if (t[j].second != 0)
          f = 1;
      if (f == 0)
        break;
      // cout<<"a";
      if (m >= t[iii].second) {
        m -= t[iii].second;
        t[iii].second = 0;
      } else {
        t[iii].second -= m;
        m = 0;
      }
      iii++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += t[i].first * t[i].second;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

// C
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int n, m;
  while (true) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<pair<int, int>> t(0); // 危険度、距離
    t.resize(11001);
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b; // 距離、北市
      t[i] = (make_pair(b, a));
    }
    sort(t.begin(), t.end(), greater<pair<int, int>>());
    int iii = 0;
    while (m > 0) {
      if (m >= t[iii].second) {
        m -= t[iii].second;
        t[iii].second = 0;
      } else {
        t[iii].second -= m;
        m = 0;
      }
      iii++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += t[i].first * t[i].second;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int main() {

  int n_intervals, budget;
  // read in number of intervals, and budget
  cin >> n_intervals >> budget;

  // pair with probability of attack and distance (of each interval)
  pair<int, int> PD[10010];

  int p, d;
  while (!(n_intervals == 0 && budget == 0)) { // while not end of input
    for (int i = 0; i < n_intervals; i++) {
      // read distance and probability
      cin >> d >> p;
      PD[i] = make_pair(p, d); // store in array
    }

    // sort the array in descending order
    sort(PD, PD + n_intervals);
    reverse(PD, PD + n_intervals);

    int i = 0;

    while (budget > PD[i].second && i < n_intervals) {
      // while budget bigger than distance of current interval
      budget -= PD[i++].second; // subtract from budget
    }

    if (i < n_intervals) {
      PD[i].second -=
          budget; // subtract from current interval budget (remainder)
    }

    int sum = 0; // sum of expected attacks
    for (; i < n_intervals; i++) {
      sum += PD[i].first * PD[i].second;
    }
    cout << sum << endl; // print output

    cin >> n_intervals >> budget; // read new input
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {

  int n_intervals, budget;
  // read in number of intervals, and budget
  cin >> n_intervals >> budget;

  // pair with probability of attack and distance (of each interval)
  pair<int, int> PD[10010];

  int p, d;
  while (n_intervals != 0 && budget != 0) { // while not end of input

    for (int i = 0; i < n_intervals; i++) {
      // read distance and probability
      cin >> d >> p;
      PD[i] = make_pair(p, d); // store in array
    }

    // sort the array ascending order
    sort(PD, PD + n_intervals);

    int i = n_intervals - 1;

    while (budget > PD[i].second) {
      // while budget bigger than distance of current interval
      budget -= PD[i--].second; // subtract from budget
      // traverse array from biggest probability to smallest
    }

    PD[i].second -= budget; // subtract from current interval budget (remainder)

    int sum = 0; // sum of expected attacks
    for (; i >= 0; i--) {
      sum += PD[i].first * PD[i].second;
    }
    cout << sum << endl; // print output

    cin >> n_intervals >> budget; // read new input
  }

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

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

int n, m;

int kitaichi(pair<int, int> *pd, int size) {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += pd[i].first * pd[i].second;
  }
  return sum;
}

int solve() {
  pair<int, int> pd[10000];
  for (int i = 0; i < n; i++) {
    int d, p;
    cin >> d >> p;
    pd[i] = make_pair(p, d);
  }
  sort(pd, pd + n);
  reverse(pd, pd + n);
  int e = kitaichi(pd, n);
  int current = 0;
  while (m > 0 && current <= n - 1) {
    if (pd[current].second < m) {
      m -= pd[current].second;
      e -= pd[current].second * pd[current].first;
      current++;
    } else {
      e -= m * pd[current].first;
      break;
    }
  }
  if (current > n - 1)
    e = 0;
  return e;
}

int main() {
  while (cin >> n >> m && n != 0) {
    cout << solve() << endl;
  }
}

Error: TLE

Fixed submission:

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

int n, m;

int kitaichi(pair<int, int> *pd, int size) {
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += pd[i].first * pd[i].second;
  }
  return sum;
}

int solve() {
  pair<int, int> pd[10000];
  for (int i = 0; i < n; i++) {
    int d, p;
    cin >> d >> p;
    pd[i] = make_pair(p, d);
  }
  sort(pd, pd + n);
  reverse(pd, pd + n);
  int e = kitaichi(pd, n);
  int current = 0;
  while (m > 0 && current < n - 1) {
    if (pd[current].second < m) {
      m -= pd[current].second;
      e -= pd[current].second * pd[current].first;
      current++;
    } else {
      e -= m * pd[current].first;
    }
  }
  if (current > n - 1)
    e = 0;
  return e;
}

int main() {
  while (cin >> n >> m && n != 0) {
    cout << solve() << endl;
  }
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

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

const int NUM = 10000;

using namespace std;

int main() {
  long long n, m;
  while (1) {
    cin >> n;
    cin >> m;
    if (n == 0 && m == 0) {
      break;
    }

    vector<pair<long long, long long>> data(NUM);
    long long total_encounter = 0;
    long long d, p;
    for (long long i = 0; i < n; i++) {
      cin >> d;
      cin >> p;
      data[i] = make_pair(p, d);
      total_encounter += d * p;
    }

    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());

    long long cost = 0;
    long long index = 0;
    long long guard;
    for (int i = 0; i < n; i++) {
      if (m <= 0)
        break;
      int guard = min(m, data[i].second);
      m -= guard;
      total_encounter -= guard * data[i].first;
    }
    cout << total_encounter << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int NUM = 10000;

using namespace std;

int main() {
  long long n, m;
  while (1) {
    cin >> n;
    cin >> m;
    if (n == 0 && m == 0) {
      break;
    }

    vector<pair<long long, long long>> data(NUM);
    long long total_encounter = 0;
    long long d, p;
    for (long long i = 0; i < n; i++) {
      cin >> d;
      cin >> p;
      data[i] = make_pair(p, d);
      total_encounter += d * p;
    }

    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());

    long long cost = 0;
    long long index = 0;
    while (1) {
      if (cost + data[index].second > m) {
        total_encounter -= (m - cost) * data[index].first;
        break;
      }
      cost += data[index].second;
      total_encounter -= data[index].first * data[index].second;
      index++;
    }
    cout << total_encounter << endl;
  }
  return 0;
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

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

const int NUM = 10000;

using namespace std;

int main() {
  long long n, m;
  while (1) {
    cin >> n;
    cin >> m;
    if (n == 0 && m == 0) {
      break;
    }

    vector<pair<long long, long long>> data(NUM);
    long long total_encounter = 0;
    long long d, p;
    for (long long i = 0; i < n; i++) {
      cin >> d;
      cin >> p;
      data[i] = make_pair(p, d);
      total_encounter += d * p;
    }

    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());

    long long index = 0;
    for (int i = 0; i < n; i++) {
      if (m < data[i].second) {
        total_encounter -= m * data[i].first;
        break;
      }
      m -= data[i].second;
      total_encounter -= data[i].first * data[i].second;
    }
    cout << total_encounter << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int NUM = 10000;

using namespace std;

int main() {
  long long n, m;
  while (1) {
    cin >> n;
    cin >> m;
    if (n == 0 && m == 0) {
      break;
    }

    vector<pair<long long, long long>> data(NUM);
    long long total_encounter = 0;
    long long d, p;
    for (long long i = 0; i < n; i++) {
      cin >> d;
      cin >> p;
      data[i] = make_pair(p, d);
      total_encounter += d * p;
    }

    sort(data.begin(), data.end());
    reverse(data.begin(), data.end());

    long long index = 0;
    while (1) {
      if (m < data[index].second) {
        total_encounter -= m * data[index].first;
        break;
      }
      m -= data[index].second;
      total_encounter -= data[index].first * data[index].second;
      index++;
    }
    cout << total_encounter << endl;
  }
  return 0;
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  ll n, m;
  while (cin >> n >> m, n + m) {
    ll ans = 0;
    vector<pair<int, int>> pii(n);
    for (int i = 0; i < n; i++) {
      cin >> pii[i].S >> pii[i].F;
      ans += pii[i].S * pii[i].F;
    }
    int po = n - 1;
    sort(pii.begin(), pii.end());
    while (po >= 0) {
      if (m - pii[po].S >= 0) {
        ans -= pii[po].F * pii[po].S;
        m -= pii[po].S;
      } else {
        ans -= pii[po].F * m;
        break;
      }
      po--;
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  ll n, m;
  while (cin >> n >> m, n + m) {
    ll ans = 0;
    vector<pair<int, int>> pii(n);
    for (int i = 0; i < n; i++) {
      cin >> pii[i].S >> pii[i].F;
      ans += pii[i].S * pii[i].F;
    }
    int po = n - 1;
    sort(pii.begin(), pii.end());
    while (m > 0) {
      if (m - pii[po].S >= 0) {
        ans -= pii[po].F * pii[po].S;
        m -= pii[po].S;
      } else {
        ans -= pii[po].F * m;
        break;
      }
      po--;
    }
    cout << ans << endl;
  }
  return 0;
}
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 (dp[j].first > 0) {
        dp[j].first--;
        m--;
      } else {
        j++;
        if (j == n)
          break;
      }
    }
    rep(i, n) { ans += dp[i].first * dp[i].second; }
    cout << ans << endl;
  }
  return 0;
}


Error: WA

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);
    rep(i, m) {
      if (dp[j].first > 0) {
        dp[j].first--;
      } else {
        j++;
      }
    }
    rep(i, n) { ans += dp[i].first * dp[i].second; }
    cout << ans << endl;
  }
  return 0;
}
Problem p01144 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef pair<int, int> P;

int n, m;
P info[10001];

int main() {
  while (cin >> n >> m, n || m) {
    long long ans = 0;

    for (int i = 0; i < n; i++)
      cin >> info[i].second >> info[i].first;

    sort(info, info + n);

    for (int i = n - 1; i >= 0; i--) {
      if (m >= info[i].second)
        m -= info[i].second;
      else {
        ans += (info[i].second - m) * info[i].first;
        m = 0;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

typedef pair<int, int> P;

int n, m;
P info[10000];

bool cmp(const P &a, const P &b) { return a.first >= b.first; }

int main() {
  while (cin >> n >> m, n || m) {
    long long ans = 0;

    for (int i = 0; i < n; i++)
      cin >> info[i].second >> info[i].first;

    sort(info, info + n, cmp);

    for (int i = 0; i < n; i++) {
      if (m >= info[i].second)
        m -= info[i].second;
      else if (m > 0) {
        ans += (info[i].second - m) * info[i].first;
        m = 0;
      }
    }

    cout << ans << endl;
  }

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

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

struct kukan {
  int p;
  int kyori;
};
bool hikaku(const kukan &right, const kukan &left) {
  return right.p == left.p ? right.kyori > left.kyori : right.p > left.p;
}

int main() {
  int n, m, d, s, res;
  kukan a;
  vector<kukan> v;
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    v.clear();
    res = 0;
    for (int i = 0; i < n; i++) {
      cin >> d >> s;
      if (s == 0)
        continue;
      a.p = s;
      a.kyori = d;
      v.push_back(a);
      res += d * s;
    }
    if (m == 0) {
      cout << res << endl;
      continue;
    }
    if (v.size() == 0) {
      cout << 0 << endl;
      continue;
    }
    sort(v.begin(), v.end(), hikaku);
    for (int i = 0; i < v.size(); i++) {
      if (m >= v[i].kyori) {
        m -= v[i].kyori;
        res -= v[i].kyori * v[i].p;
        if (m == 0)
          break;
      } else if (m < v[i].kyori) {
        res -= v[i].p * m;
        break;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  int n, m, l, k, c, count;
  vector<int> a;
  while (1) {
    cin >> n >> m;
    if (n == 0)
      break;
    a.clear();
    for (int i = 0; i < n; i++) {
      cin >> l >> c;

      for (k = 0; k < l; k++) {
        a.push_back(c);
      }
    }
    sort(a.begin(), a.end());
    count = 0;
    if (a.size() <= m) {
      cout << 0 << endl;
      continue;
    }
    for (int i = 0; i < a.size() - m; i++) {
      count += a[i];
    }
    cout << count << endl;
  }
  return 0;
}