prithivMLmods/Coder-Stat huggingface dataset:
Problem p03102 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, m, c;
  cin >> n >> m >> c;

  vector<int> B(m);
  for (int i = 0; i < m; ++i) {
    cin >> B[i];
  }
  vector<vector<int>> A(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> A[n][m];
    }
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      cnt += A[i][j] * B[j];
    }
    if ((cnt + c) > 0) {
      ans++;
    }
  }

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


Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, m, c;
  cin >> n >> m >> c;

  vector<int> B(m);
  for (int i = 0; i < m; ++i) {
    cin >> B[i];
  }
  vector<vector<int>> A(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> A[i][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      cnt += A[i][j] * B[j];
    }
    if ((cnt + c) > 0) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03102 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

import numpy as np

N, M, C = map(int, input().split())
B = np.ndarray([M, 1])
B = list(map(int, input().split()))
A = np.ndarray([N, M])
for i in range(N):
    A[i, :] = list(map(int, input().split()))

ans = sum((A @ B + C) > 0)

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

import numpy as np

N, M, C = map(int, input().split())
B = np.ndarray([M, 1])
B = list(map(int, input().split()))
A = np.ndarray([N, M])
for i in range(N):
    A[i, :] = list(map(int, input().split()))

ans = sum((np.dot(A, B) + C) > 0)

print(ans)
Problem p03102 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  /*input*/
  int n, m, c;
  cin >> n >> m >> c;
  int *b = new int[m];
  int **a = new int *[n];
  for (int i = 0; i < n; i++) {
    a[i] = new int[m];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  /*calculation*/
  int o = 0;
  for (int i = 0; i < n; i++) {
    int wa = 0;
    for (int j = 0; j < m; j++) {
      wa += a[i][j] * b[j];
    }
    wa += c;
    if (wa > 0) {
      o++;
    }
  }
  /*output*/
  cout << o << endl;
  delete[] b;
  for (int i = 0; i < m; i++) {
    delete[] a[i];
  }
  delete[] a;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  /*input*/
  int n, m, c;
  cin >> n >> m >> c;
  int *b = new int[m];
  int **a = new int *[n];
  for (int i = 0; i < n; i++) {
    a[i] = new int[m];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  /*calculation*/
  int o = 0;
  for (int i = 0; i < n; i++) {
    int wa = 0;
    for (int j = 0; j < m; j++) {
      wa += a[i][j] * b[j];
    }
    wa += c;
    if (wa > 0) {
      o++;
    }
  }
  /*output*/
  cout << o << endl;
  return 0;
}
Problem p03102 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(n);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  int ans = 0;
  int a;

  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      cin >> a;
      sum += a * b[j];
    }
    if (sum + c > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  int ans = 0;
  int a;

  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      cin >> a;
      sum += a * b[j];
    }
    if (sum + c > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03102 (C++)

Buggy submission (status: Runtime Error):
//  main.cpp
//  CppTest

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

int main(int argc, const char *argv[]) {

  // input from txt （提出時にこの箇所は削除すること）
  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());

  /////////////////////
  // Write code below /
  /////////////////////
  int N, M, C;
  cin >> N >> M >> C;

  vector<int> B(M);
  for (int i = 0; i < M; i++)
    cin >> B.at(i);

  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }

  int correct_answer_num = 0;
  for (int i = 0; i < N; i++) {
    int answer = 0;
    for (int j = 0; j < M; j++) {
      answer += A.at(i).at(j) * B.at(j);
    }
    answer += C;
    if (answer > 0) {
      correct_answer_num++;
    }
  }

  cout << correct_answer_num << endl;

  return 0;
}


Fixed submission:
//  main.cpp
//  CppTest

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

int main(int argc, const char *argv[]) {

  // cinを高速にするためのおまじない
  cin.tie(0);
  ios::sync_with_stdio(false);

  /////////////////////
  // Write code below /
  /////////////////////
  int N, M, C;
  cin >> N >> M >> C;

  vector<int> B(M);
  for (int i = 0; i < M; i++)
    cin >> B.at(i);

  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }

  int correct_answer_num = 0;
  for (int i = 0; i < N; i++) {
    int answer = 0;
    for (int j = 0; j < M; j++) {
      answer += A.at(i).at(j) * B.at(j);
    }
    answer += C;
    if (answer > 0) {
      correct_answer_num++;
    }
  }

  cout << correct_answer_num << endl;

  return 0;
}
Problem p03102 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> B(N);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    int ans = 0;
    for (int j = 0; j < M; j++) {
      ans = ans + A.at(i).at(j) * B.at(j);
    }
    ans = ans + C;
    if (ans > 0) {
      count++;
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<vector<int>> A(N, vector<int>(M));
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    int ans = 0;
    for (int j = 0; j < M; j++) {
      ans = ans + A.at(i).at(j) * B.at(j);
    }
    ans = ans + C;
    if (ans > 0) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p03102 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int n, m, c, num = 0;
  cin >> n >> m >> c;
  int array[20][20];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> array[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    int sum = c;
    for (int j = 0; j < m; j++) {
      sum += array[0][j] * array[i][j];
    }
    if (sum > 0)
      num += 1;
  }
  cout << num << endl;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int n, m, c, num = 0;
  cin >> n >> m >> c;
  int array[21][21];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> array[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    int sum = c;
    for (int j = 0; j < m; j++) {
      sum += array[0][j] * array[i][j];
    }
    if (sum > 0)
      num += 1;
  }
  cout << num << endl;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e3 + 17;
ll cnt, lnt, mn = N, mx, a[N], n, m, k, x, y, ans, sum;
pair<ll, ll> pr[N];
vector<ll> v, v2, v3;
map<ll, ll> mp;
bool used[N], t1, t2;
vector<string> sv;

int main() {
  cin >> n >> m;
  for (ll i = 0; i < n; i++) {
    cin >> pr[i].first >> pr[i].second;
  }
  sort(pr, pr + n);
  for (ll i = 0; i < n; i++) {
    if (m > pr[i].second and m > 0 and !used[i]) {
      ans += pr[i].first * pr[i].second;
      m -= pr[i].second;
      used[i] = true;
    }
    if (m <= pr[i].second and m > 0 and !used[i]) {
      ans += pr[i].first * m;
      m = 0;
      used[i] = true;
    }
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e5 + 17;
ll cnt, lnt, mn = N, mx, a[N], n, m, k, x, y, ans, sum;
pair<ll, ll> pr[N];
vector<ll> v, v2, v3;
map<ll, ll> mp;
bool used[N], t1, t2;
vector<string> sv;

int main() {
  cin >> n >> m;
  for (ll i = 0; i < n; i++) {
    cin >> pr[i].first >> pr[i].second;
  }
  sort(pr, pr + n);
  for (ll i = 0; i < n; i++) {
    if (m > pr[i].second and m > 0 and !used[i]) {
      ans += pr[i].first * pr[i].second;
      m -= pr[i].second;
      used[i] = true;
    }
    if (m <= pr[i].second and m > 0 and !used[i]) {
      ans += pr[i].first * m;
      m = 0;
      used[i] = true;
    }
  }
  cout << ans;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 28;
vector<pair<int, int>> p;
long long ans;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    p.push_back({a, b});
  }
  sort(p.begin(), p.end());
  int c = 0;
  int i = 0;
  while (c + p[i].second <= m) {
    c += p[i].second;
    ans += (long long)p[i].first * p[i].second;
    i++;
  }
  ans += (long long)p[i].first * (m - c);
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 28;
vector<pair<int, int>> p;
long long ans;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    p.push_back({a, b});
  }
  sort(p.begin(), p.end());
  int c = 0;
  int i = 0;
  while (c + p[i].second < m) {
    c += p[i].second;
    ans += (long long)p[i].first * p[i].second;
    i++;
  }
  ans += (long long)p[i].first * (m - c);
  cout << ans;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;
int n, m, a, b;
vector<pair<int, int>> vec;
long long ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    vec.pb({a, b});
  }
  sort(vec.begin(), vec.end());
  vec.pb({0, 0});
  int cur = 0, cnt = 0;
  while (1) {
    if (cnt + vec[cur].se <= m) {
      cnt += vec[cur].se;
      ans += vec[cur].fi * 1LL * vec[cur].se;
    } else {
      ans += vec[cur].fi * 1LL * (m - cnt);
      break;
    }
    cur++;
  }
  cout << ans << "\n";
  // system("pause");
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;
int n, m, a, b;
vector<pair<int, int>> vec;
long long ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    vec.pb({a, b});
  }
  sort(vec.begin(), vec.end());
  vec.pb({0, 1});
  int cur = 0, cnt = 0;
  while (1) {
    if (cnt + vec[cur].se <= m) {
      cnt += vec[cur].se;
      ans += vec[cur].fi * 1LL * vec[cur].se;
    } else {
      ans += vec[cur].fi * 1LL * (m - cnt);
      break;
    }
    cur++;
  }
  cout << ans << "\n";
  // system("pause");
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 300;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

struct kien {
  ll x, y;
};
kien a[e];

bool lf(const kien &p, const kien &q) { return p.x < q.x; }

int main() {
  ll n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  sort(a + 1, a + n + 1, lf);
  ll s = 0;
  for (int i = 1; i <= n; i++) {
    s += a[i].x * min(m, a[i].y);
    m -= min(m, a[i].y);
    if (m == 0)
      break;
  }
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6 + 69;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

struct kien {
  ll x, y;
};
kien a[e];

bool lf(const kien &p, const kien &q) { return p.x < q.x; }

int main() {
  ll n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  sort(a + 1, a + n + 1, lf);
  ll s = 0;
  for (int i = 1; i <= n; i++) {
    s += a[i].x * min(m, a[i].y);
    m -= min(m, a[i].y);
    if (m == 0)
      break;
  }
  cout << s;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
long long n, m, ans = 0;
struct Node {
  int p, d;
  bool operator<(Node b) { return p < b.p; }
} a[3000];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> a[i].p >> a[i].d;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    while (m && a[i].d)
      --m, --a[i].d, ans += a[i].p;
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
long long n, m, ans = 0;
struct Node {
  int p, d;
  bool operator<(Node b) { return p < b.p; }
} a[300000];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> a[i].p >> a[i].d;
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    while (m && a[i].d)
      --m, --a[i].d, ans += a[i].p;
  }
  cout << ans;
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  rep(i, n) cin >> a[i] >> b[i];
  vector<pair<int, int>> pa(n);
  rep(i, n) pa[i] = make_pair(a[i], b[i]);
  sort(pa.begin(), pa.end());

  ll ans = 0;
  rep(i, n) {
    int buy = min(m, pa[i].second);
    ans += (ll)buy * pa[i].first;
    m -= buy;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  vector<pair<int, int>> pa(n);
  rep(i, n) pa[i] = make_pair(a[i], b[i]);
  sort(pa.begin(), pa.end());

  ll ans = 0;
  rep(i, n) {
    int buy = min(m, pa[i].second);
    ans += (ll)buy * pa[i].first;
    m -= buy;
  }
  cout << ans << endl;
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin >>
#define Z class
#define ll long long
#define ln cout << '\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n", a)
#define mem(a) memset(a, 0, sizeof(a))
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++)
template <Z A> void pr(A a) {
  cout << a;
  ln;
}
template <Z A, Z B> void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <Z A, Z B, Z C> void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <Z A, Z B, Z C, Z D> void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <Z A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  ln;
}
ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; }
const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
         dy[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;

void Main() {
  ll n, m;
  cin >> n >> m;
  P a[n];
  rep(i, n) cin >> a[i].F >> a[i].S;
  sort(a, a + n);
  ll ans = 0;
  rep(i, n) {
    rep(j, a[i].S) {
      if (m) {
        m--;
        ans += a[i].F;
      }
    }
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin >>
#define Z class
#define ll long long
#define ln cout << '\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n", a)
#define mem(a) memset(a, 0, sizeof(a))
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++)
template <Z A> void pr(A a) {
  cout << a;
  ln;
}
template <Z A, Z B> void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <Z A, Z B, Z C> void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <Z A, Z B, Z C, Z D> void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <Z A> void PR(A a, ll n) {
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  ln;
}
ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; }
const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
         dy[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;

void Main() {
  ll n, m;
  cin >> n >> m;
  P a[n];
  rep(i, n) cin >> a[i].F >> a[i].S;
  sort(a, a + n);
  ll ans = 0;
  rep(i, n) {
    ll x = min(m, a[i].S);
    m -= x;
    ans += a[i].F * x;
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

struct AB {
  long long a;
  long long b;
};

bool asc(const AB &left, const AB &right) {
  if (left.a != right.a)
    return left.a < right.a;
}

int main() {
  int N, M, tmp1, tmp2, get;
  long long cost;
  AB tmp_AB;
  vector<AB> v;

  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> tmp1 >> tmp2;
    tmp_AB.a = tmp1;
    tmp_AB.b = tmp2;
    v.push_back(tmp_AB);
  }

  cost = 0;
  get = 0;
  int min = 0, tmp_num;
  sort(v.begin(), v.end(), asc);
  while (get < M) {
    tmp_num = v[min].b;
    if ((M - get) <= tmp_num) { // 終了できるとき
      cost += v[min].a * (M - get);
      break;
    } else {
      cost += v[min].a * v[min].b;
      get += v[min].b;
    }
    min++;
  }

  cout << cost;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

struct AB {
  long long a;
  long long b;
};

bool asc(const AB &left, const AB &right) { return left.a < right.a; }

int main() {
  int N, M, tmp1, tmp2, get;
  long long cost;
  AB tmp_AB;
  vector<AB> v;

  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> tmp1 >> tmp2;
    tmp_AB.a = tmp1;
    tmp_AB.b = tmp2;
    v.push_back(tmp_AB);
  }

  cost = 0;
  get = 0;
  int min = 0, tmp_num;
  sort(v.begin(), v.end(), asc);
  while (get < M) {
    tmp_num = v[min].b;
    if ((M - get) <= tmp_num) { // 終了できるとき
      cost += v[min].a * (M - get);
      break;
    } else {
      cost += v[min].a * v[min].b;
      get += v[min].b;
    }
    min++;
  }

  cout << cost;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {

  ll N, M;
  Scll2(N, M);
  vector<pair<ll, ll>> d(N);
  Rep(i, N) { Scll2(d[i].second, d[i].first); }

  sort(d.begin(), d.end());

  ll ans = 0;
  for (int i = 0; M; i++) {
    if (M < d[i].second) {
      d[i].second = M;
    }
    M -= d[i].second;
    ans += d[i].first * d[i].second;
  }

  printf("%llu\n", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x, y) scanf("%llu%llu", &x, &y)
#define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x, y) for (int x = 0; x < y; x++)
#define Repe(x, y, z) for (int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n");
// }}} 2

// }}} 1

int main() {

  ll N, M;
  Scll2(N, M);
  vector<pair<ll, ll>> d(N);
  Rep(i, N) { Scll2(d[i].first, d[i].second); }

  sort(d.begin(), d.end());

  ll ans = 0;
  for (int i = 0; M; i++) {
    if (M < d[i].second) {
      d[i].second = M;
    }
    M -= d[i].second;
    ans += d[i].first * d[i].second;
  }

  printf("%llu\n", ans);

  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int64_t, int64_t>> vec(N);
  for (int i = 0; i < N; i++) {
    int64_t O, P;
    cin >> O >> P;
    vec.at(i) = make_pair(O, P);
  }
  sort(vec.begin(), vec.end());
  int64_t total = 0;
  int64_t ans = 0;
  int i = 0;
  bool shokai = false;
  while (true) {
    if (vec.at(i).second >= M) {
      shokai = true;
      break;
    } else {
      total += vec.at(i).second;
      ans += vec.at(i).first * vec.at(i).second;
      if (total + vec.at(i + 1).second > M) {
        break;
      } else {
        i++;
      }
    }
  }
  if (shokai) {
    ans += (M - total) * vec.at(i).first;
  } else {
    ans += (M - total) * vec.at(i + 1).first;
  }
  cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int64_t, int64_t>> vec(N);
  for (int i = 0; i < N; i++) {
    int64_t O, P;
    cin >> O >> P;
    vec.at(i) = make_pair(O, P);
  }
  sort(vec.begin(), vec.end());
  int64_t total = 0;
  int64_t ans = 0;
  int i = 0;
  bool shokai = false;
  while (true) {
    if (vec.at(i).second >= M) {
      shokai = true;
      break;
    } else {
      total += vec.at(i).second;
      ans += vec.at(i).first * vec.at(i).second;
      if (total + vec.at(i + 1).second >= M) {
        break;
      } else {
        i++;
      }
    }
  }
  if (shokai) {
    ans += (M - total) * vec.at(i).first;
  } else {
    ans += (M - total) * vec.at(i + 1).first;
  }
  cout << ans << endl;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

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

  vector<int> A(N), B(M);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  vector<pair<int, int>> AB(N);
  for (int i = 0; i < N; i++) {
    AB[i] = make_pair(A[i], B[i]);
  }
  sort(AB.begin(), AB.end());

  long long result = 0;
  for (int i = 0; i < N; i++) {
    int buy = min(M, AB[i].second);
    result += (long long)buy * AB[i].first;
    M -= buy;
  }
  cout << result << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

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

  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  vector<pair<int, int>> AB(N);
  for (int i = 0; i < N; i++) {
    AB[i] = make_pair(A[i], B[i]);
  }
  sort(AB.begin(), AB.end());

  long long result = 0;
  for (int i = 0; i < N; i++) {
    int buy = min(M, AB[i].second);
    result += (long long)buy * AB[i].first;
    M -= buy;
  }
  cout << result << endl;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int n, m;

struct drink {
  int cou;
  long long mon;
} a[10001];

bool cmp(struct drink a, struct drink b) { return a.mon < b.mon; }

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%lld%d", &a[i].mon, &a[i].cou);
  sort(a + 1, a + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; m > 0; i++) {
    if (m >= a[i].cou) {
      m -= a[i].cou;
      ans += a[i].cou * a[i].mon;
    } else {
      ans += m * a[i].mon;
      m = 0;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int n, m;

struct drink {
  int cou;
  long long mon;
} a[100001];

bool cmp(struct drink a, struct drink b) { return a.mon < b.mon; }

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%lld%d", &a[i].mon, &a[i].cou);
  sort(a + 1, a + n + 1, cmp);
  long long ans = 0;
  for (int i = 1; m > 0; i++) {
    if (m >= a[i].cou) {
      m -= a[i].cou;
      ans += a[i].cou * a[i].mon;
    } else {
      ans += m * a[i].mon;
      m = 0;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie();                                                                   \
  cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll n, m, ans = 0, banyak = 0;

struct struk {
  ll a, b;
};
struk minum[105];

bool cmp(struk s1, struk s2) { return s1.a < s2.a; }

int main() {
  IOS cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> minum[i].a >> minum[i].b;
  }
  sort(minum, minum + n, cmp);
  for (int i = 0; i < n; i++) {
    while (minum[i].b > 0 && banyak < m) {
      ans += minum[i].a;
      banyak++;
      minum[i].b--;
    }
  }
  cout << ans << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie();                                                                   \
  cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll n, m, ans = 0, banyak = 0;

struct struk {
  ll a, b;
};
struk minum[nax];

bool cmp(struk s1, struk s2) { return s1.a < s2.a; }

int main() {
  IOS cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> minum[i].a >> minum[i].b;
  }
  sort(minum, minum + n, cmp);
  for (int i = 0; i < n; i++) {
    while (minum[i].b > 0 && banyak < m) {
      ans += minum[i].a;
      banyak++;
      minum[i].b--;
    }
  }
  cout << ans << '\n';
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 20;

pii a[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; ++i)
    scanf("%d%d", &a[i].first, &a[i].second);

  sort(a, a + n);

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (m <= a[i].second) {
      ans += m * 1LL * a[i].first;
      m = 0;
      break;
    } else {
      ans += a[i].second * 1LL * a[i].first;
      m -= a[i].second;
    }
  }

  printf("%lld", ans);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 1e5;

pii a[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; ++i)
    scanf("%d%d", &a[i].first, &a[i].second);

  sort(a, a + n);

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (m <= a[i].second) {
      ans += m * 1LL * a[i].first;
      m = 0;
      break;
    } else {
      ans += a[i].second * 1LL * a[i].first;
      m -= a[i].second;
    }
  }

  printf("%lld", ans);
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
int main() {
  int n, m;
  pair<int, int> super[10000];
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    scanf("%d %d", &super[i].first, &super[i].second);
  sort(super, super + n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (m == 0)
      break;
    if (m >= super[i].second) {
      m -= super[i].second;
      sum += (long long)super[i].first * super[i].second;
    } else {
      sum += (long long)super[i].first * m;
      m = 0;
    }
  }
  printf("%lld\n", sum);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
int main() {
  int n, m;
  pair<int, int> super[100000];
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    scanf("%d %d", &super[i].first, &super[i].second);
  sort(super, super + n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (m == 0)
      break;
    if (m >= super[i].second) {
      m -= super[i].second;
      sum += (long long)super[i].first * super[i].second;
    } else {
      sum += (long long)super[i].first * m;
      m = 0;
    }
  }
  printf("%lld\n", sum);
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define P pair<ll, ll>
using namespace std;
bool comparator(P &A, P &B) { return A.first <= B.first; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  sort(arr.begin(), arr.end(), comparator);
  ll cost = 0;
  int i = 0;
  while (i < n && m > 0) {
    if (m <= arr[i].second) {
      cost += (m * arr[i].first);
      m = 0;
    } else {
      cost += (arr[i].first * arr[i].second);
      m -= arr[i].second;
    }
    i++;
  }
  cout << cost << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define P pair<ll, ll>
using namespace std;
bool comparator(P &A, P &B) { return A.first < B.first; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  sort(arr.begin(), arr.end(), comparator);
  ll cost = 0;
  int i = 0;
  while (i < n && m > 0) {
    if (m <= arr[i].second) {
      cost += (m * arr[i].first);
      m = 0;
    } else {
      cost += (arr[i].first * arr[i].second);
      m -= arr[i].second;
    }
    i++;
  }
  cout << cost << endl;
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N), B(N);
  map<ll, ll> C;
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i);
    C[A.at(i)] += B.at(i);
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  ll cnt = 0;
  for (ll i = 0; i < 1000000000; i++) {
    ans += i * C[i];
    cnt += C[i];
    if (cnt >= M) {
      cout << ans - (cnt - M) * i << endl;
      break;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N), B(N);
  map<ll, ll> C;
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i);
    C[A.at(i)] += B.at(i);
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  ll cnt = 0;
  ll judge;
  for (ll i : A) {
    if (judge != i) {
      ans += i * C[i];
      cnt += C[i];
    }
    judge = i;
    if (cnt >= M) {
      cout << ans - (cnt - M) * i << endl;
      break;
    }
  }
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int $(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

signed main() {
  int a, b, d = 0;
  cin >> a >> b;
  vector<pair<int, int>> c(a);
  for (int i = 0; i < a; i++)
    cin >> c.at(i).first >> c.at(i).second;
  sort(c.begin(), c.end());
  for (int i = 0; b > 0; i++) {
    if (b >= c.at(i).second) {
      b -= c.at(i).second;
      d += c.at(i).second * c.at(i).first;
    } else {
      d += b * c.at(i).first;
    }
  }
  cout << d << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int $(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}

signed main() {
  int a, b, d = 0;
  cin >> a >> b;
  vector<pair<int, int>> c(a);
  for (int i = 0; i < a; i++)
    cin >> c.at(i).first >> c.at(i).second;
  sort(c.begin(), c.end());
  for (int i = 0; b > 0; i++) {
    if (b >= c.at(i).second) {
      b -= c.at(i).second;
      d += c.at(i).second * c.at(i).first;
    } else {
      d += b * c.at(i).first;
      break;
    }
  }
  cout << d << endl;
}
Problem p03103 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m = map(int, input().split())
money = 0
li = []

for i in range(n):
    li.append(list(map(int, input().split())))
li.sort()

while 0 < m:
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)


Fixed submission:
n, m = map(int, input().split())
money = 0
li = []

for i in range(n):
    li.append(list(map(int, input().split())))
li.sort()

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)
Problem p03103 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)].sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if pm > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]


Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if pm > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4 + 10;
typedef struct Node {
  ll a, b;
  bool operator<(const Node &t) const { return a < t.a; }
} Node;
Node p[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &p[i].a, &p[i].b);
  }
  sort(p + 1, p + 1 + n);
  ll ans = 0;
  ll cur = 0;
  for (int i = 1; i <= n; i++) {
    if (cur + p[i].b <= m) {
      ans = ans + p[i].a * p[i].b;
      cur = cur + p[i].b;
    } else {
      ll t = (m - cur) * p[i].a;
      ans = ans + t;
      break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
typedef struct Node {
  ll a, b;
  bool operator<(const Node &t) const { return a < t.a; }
} Node;
Node p[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld", &p[i].a, &p[i].b);
  }
  sort(p + 1, p + 1 + n);
  ll ans = 0;
  ll cur = 0;
  for (int i = 1; i <= n; i++) {
    if (cur + p[i].b <= m) {
      ans = ans + p[i].a * p[i].b;
      cur = cur + p[i].b;
    } else {
      ll t = (m - cur) * p[i].a;
      ans = ans + t;
      break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define DIM 107
#define DIMM 2007
#define INF 10000000000007.0
#define X 2000000007
#define epc 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO 10009
const long double gr = (1 + sqrt(5)) / 2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I, I> pII;
typedef pair<ll, ll> pllll;
typedef pair<ld, ld> pldld;
typedef pair<ll, pllll> pllpllll;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n, m;
ll res;
pllll a[DIM];

int main() {
  // freopen("events.in", "r", stdin);
  // freopen("events.out", "w", stdout);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // cout<<"ops"<<endl;

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i].first >> a[i].second;
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (a[i].second <= m) {
      res += (a[i].first * a[i].second);
      m -= a[i].second;
    } else {
      res += (a[i].first * m);
      m = 0;
    }
    if (m == 0)
      break;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define DIM 100007
#define DIMM 2007
#define INF 10000000000007.0
#define X 2000000007
#define epc 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO 10009
const long double gr = (1 + sqrt(5)) / 2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I, I> pII;
typedef pair<ll, ll> pllll;
typedef pair<ld, ld> pldld;
typedef pair<ll, pllll> pllpllll;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n, m;
ll res;
pllll a[DIM];

int main() {
  // freopen("events.in", "r", stdin);
  // freopen("events.out", "w", stdout);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // cout<<"ops"<<endl;

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i].first >> a[i].second;
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (a[i].second <= m) {
      res += (a[i].first * a[i].second);
      m -= a[i].second;
    } else {
      res += (a[i].first * m);
      m = 0;
    }
    if (m == 0)
      break;
  }
  cout << res << endl;
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    A[i].first = tmp1;
    A[i].second = tmp2;
  }
  // for (int i = 0; i < N; i++)
  //{
  //     cout << i << "th" << A[i].first << endl;
  // }
  sort(A.begin(), A.end());
  //    for (int i = 0; i < N; i++)
  //    {
  //        cout << i << "th" << A[i].first << endl;
  //    }
  //    reverse(A.begin(), A.end());
  //    for (int i = 0; i < N; i++)
  //    {
  //        cout << i << "th" << A[i].first << endl;
  //    }
  int i = -1;
  long long cnt = 0;
  while (M >= 0) {
    i++;
    int M_tmp = M;
    M_tmp -= A[i].second;
    if (M_tmp <= 0) {
      cnt += (long long)M * A[i].first;
    } else {
      cnt += (long long)A[i].second * A[i].first;
    }
    M -= A[i].second;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    A[i].first = tmp1;
    A[i].second = tmp2;
  }
  // for (int i = 0; i < N; i++)
  //{
  //     cout << i << "th" << A[i].first << endl;
  // }
  sort(A.begin(), A.end());
  //    for (int i = 0; i < N; i++)
  //    {
  //        cout << i << "th" << A[i].first << endl;
  //    }
  //    reverse(A.begin(), A.end());
  //    for (int i = 0; i < N; i++)
  //    {
  //        cout << i << "th" << A[i].first << endl;
  //    }
  int i = -1;
  long long cnt = 0;
  while (M > 0) {
    i++;
    int M_tmp = M;
    M_tmp -= A[i].second;
    if (M_tmp <= 0) {
      cnt += (long long)M * A[i].first;
    } else {
      cnt += (long long)A[i].second * A[i].first;
    }
    M -= A[i].second;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

typedef unsigned long long int ll;
typedef std::pair<ll, ll> pii;
using namespace std;

bool s(pii a, pii b) { return a.first <= b.first; }

int main() {
  int N, M;
  vector<pii> v;
  cin >> N >> M;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end(), s);
  ll c = 0;
  for (auto i : v) {
    ans += (ll)(i.first * i.second);
    c += i.second;
    if (c >= M) {
      ans -= (ll)(i.first * (c - M));
      cout << ans;
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>

typedef unsigned long long int ll;
typedef std::pair<ll, ll> pii;
using namespace std;

bool s(pii a, pii b) { return a.first <= b.first; }

int main() {
  int N, M;
  vector<pii> v;
  cin >> N >> M;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  stable_sort(v.begin(), v.end(), s);
  ll c = 0;
  for (auto i : v) {
    ans += (ll)(i.first * i.second);
    c += i.second;
    if (c >= M) {
      ans -= (ll)(i.first * (c - M));
      cout << ans;
      return 0;
    }
  }
}
Problem p03103 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> vec;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    vec[i].first = a;
    vec[i].second = b;
  }

  sort(ALL(vec));

  ll money = 0;
  ll count = 0;
  for (int i = 0; i < n; i++) {
    bool fin = false;
    if (count + vec[i].second >= m) {
      for (int j = 0; j < vec[i].second; j++) {
        money += vec[i].first;
        count++;
        if (count == m) {
          fin = true;
          break;
        }
      }
    }
    if (fin)
      break;
    money += vec[i].first * vec[i].second;
    count += vec[i].second;
  }

  cout << money << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> vec;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    vec.push_back(make_pair(a, b));
  }

  sort(ALL(vec));

  ll money = 0;
  ll count = 0;
  for (int i = 0; i < n; i++) {
    bool fin = false;
    if (count + vec[i].second >= m) {
      for (int j = 0; j < vec[i].second; j++) {
        money += vec[i].first;
        count++;
        if (count == m) {
          fin = true;
          break;
        }
      }
    }
    if (fin)
      break;
    money += vec[i].first * vec[i].second;
    count += vec[i].second;
  }

  cout << money << endl;
}
Problem p03103 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> v(n);

  rep(i, n) {
    pair<int, int> ab;
    cin >> ab.first >> ab.second;
    v[i] = ab;
  }

  sort(all(v));
  ll sum = 0;

  rep(i, n) {
    auto ab = v[i];
    for (int j = 1; j <= ab.second; ++j) {
      --m;
      sum += ab.first;
      if (m == 0) {
        cout << sum;
      }
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

using namespace std;

typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> v(n);

  rep(i, n) {
    pair<int, int> ab;
    cin >> ab.first >> ab.second;
    v[i] = ab;
  }

  sort(all(v));
  ll sum = 0;

  rep(i, n) {
    auto ab = v[i];
    for (int j = 1; j <= ab.second; ++j) {
      --m;
      sum += ab.first;
      if (m == 0) {
        cout << sum;
        return 0;
      }
    }
  }
}