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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int D, G;
int p[10];
int c[10];
pair<int, int> m[10];
int ans = 1e8;
/*
void func(int sum,int res,int Index){
    if(sum>=G){
        ans=min(res,ans);
        return;
    }
    if(Index==D||res>=ans)return ;
    for(int i=0;i<=p[Index];i++){
        int temp =0;
        if(p[Index]==i)temp=c[Index];
        func((Index+1)*100*i+temp+sum,res+i,Index+1);
    }
    return ;
}*/

void func(int sum, int res, int index, long flag) {
  if (sum >= G) {
    ans = min(ans, res);
    return;
  }
  if (index == D) {
    int fi = D - 1;
    while (G > sum) {
      if (!(flag & (1 << fi))) {
        for (int j = 0; j < p[fi]; j++) {
          sum += (fi + 1) * 100;
          res++;
          if (sum >= G)
            break;
        }
        flag ^= (1 << (fi));
      }
      fi--;
    }
    ans = min(ans, res);
    return;
  }
  flag ^= (1 << index);
  func(m[index].first + sum, m[index].second + res, index + 1, flag);
  flag ^= (1 << index);
  func(sum, res, index + 1, flag);
  return;
}

int main() {
  cin >> D >> G;
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
    m[i].first = p[i] * (i + 1) * 100 + c[i];
    m[i].second = p[i];
  }

  func(0, 0, 0, 0);

  cout << ans << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int D, G;
int p[10];
int c[10];
pair<int, int> m[10];
int ans = 1e8;
/*
void func(int sum,int res,int Index){
    if(sum>=G){
        ans=min(res,ans);
        return;
    }
    if(Index==D||res>=ans)return ;
    for(int i=0;i<=p[Index];i++){
        int temp =0;
        if(p[Index]==i)temp=c[Index];
        func((Index+1)*100*i+temp+sum,res+i,Index+1);
    }
    return ;
}*/

void func(int sum, int res, int index, long flag) {
  if (sum >= G) {
    ans = min(ans, res);
    return;
  }
  if (index == D) {
    int fi = D - 1;
    while (G > sum && res <= ans) {
      if (!(flag & (1 << fi))) {
        for (int j = 0; j < p[fi]; j++) {
          sum += (fi + 1) * 100;
          res++;
          if (sum >= G)
            break;
        }
        flag ^= (1 << (fi));
      }
      fi--;
    }
    ans = min(ans, res);
    return;
  }
  flag ^= (1 << index);
  func(m[index].first + sum, m[index].second + res, index + 1, flag);
  flag ^= (1 << index);
  func(sum, res, index + 1, flag);
  return;
}

int main() {
  cin >> D >> G;
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
    m[i].first = p[i] * (i + 1) * 100 + c[i];
    m[i].second = p[i];
  }

  func(0, 0, 0, 0);

  cout << ans << endl;
}
Problem p03290 (C++)

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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D), c(D);
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  int ans = 10000000;
  for (int s = 0; s < (1 << D); s++) {
    int SUM = 0, NUM = 0, rest_i = -1;
    for (int i = 0; i < D; i++) {
      if (s >> i & 1) {
        SUM += p[i] * (i + 1) + c[i];
        NUM += p[i];
      } else {
        rest_i = i;
      }
    }
    if (SUM < G) {
      int need = (G - SUM) / (100 * (rest_i + 1));
      if ((G - SUM) % (100 * (rest_i + 1)) > 0)
        need++;
      if (need < p[rest_i])
        NUM += need;
      else
        NUM = 10000000;
    }
    ans = min(NUM, ans);
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D), c(D);
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  int ans = 10000000;
  for (int s = 0; s < (1 << D); s++) {
    int SUM = 0, NUM = 0, rest_i = -1;
    for (int i = 0; i < D; i++) {
      if (s >> i & 1) {
        SUM += p[i] * (i + 1) * 100 + c[i];
        NUM += p[i];
      } else {
        rest_i = i;
      }
    }
    if (SUM < G) {
      int need = (G - SUM) / (100 * (rest_i + 1));
      if ((G - SUM) % (100 * (rest_i + 1)) > 0)
        need++;
      if (need < p[rest_i])
        NUM += need;
      else
        NUM = 10000000;
    }
    ans = min(NUM, ans);
  }
  cout << ans << endl;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template <typename T> void cmax(T &a, T b) { a = max(a, b); }
template <typename T> void cmin(T &a, T b) { a = min(a, b); }

vector<vector<int>> dp(20, vector<int>(100005, INF));
signed main() {
  int d, g;
  cin >> d >> g;
  g /= 100;
  vector<int> p(d + 1), c(d + 1);
  for (int i = 1; i <= d; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= d; i++) {
    rep(j, g + 1) {
      if (dp[i - 1][j] < INF) {
        for (int k = 0; k <= p[i]; k++) {
          int sum = i * k + (k == p[i] ? c[i] : 0);
          cmin(dp[i][min(g, j + sum)], dp[i - 1][j] + k);
        }
        cmin(dp[i][min(g, j + i * p[i])], dp[i - 1][j] + p[i]);
      }
    }
  }

  cout << dp[d][g] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template <typename T> void cmax(T &a, T b) { a = max(a, b); }
template <typename T> void cmin(T &a, T b) { a = min(a, b); }

vector<vector<int>> dp(20, vector<int>(200005, INF));
signed main() {
  int d, g;
  cin >> d >> g;
  g /= 100;
  vector<int> p(d + 1), c(d + 1);
  for (int i = 1; i <= d; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  dp[0][0] = 0;
  for (int i = 1; i <= d; i++) {
    rep(j, g + 1) {
      if (dp[i - 1][j] < INF) {
        for (int k = 0; k <= p[i]; k++) {
          int sum = i * k + (k == p[i] ? c[i] : 0);
          cmin(dp[i][min(g, j + sum)], dp[i - 1][j] + k);
        }
        cmin(dp[i][min(g, j + i * p[i])], dp[i - 1][j] + p[i]);
      }
    }
  }

  cout << dp[d][g] << endl;

  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
//
// Created by Huang,Zhiqiang on 2018/8/13.
//

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

const int INF = int(1e9);
int n, goal;
int con[15][2];
int dp[15][int(1e5)];

int DP(int x, int y) {
  if (y <= 0)
    return 0;
  if (x < 1)
    return INF;
  if (dp[x][y] != -1)
    return dp[x][y];
  dp[x][y] = INF;
  for (int i = 0; i < con[x][0]; i++)
    dp[x][y] = min(dp[x][y], DP(x - 1, y - i * x) + i);
  dp[x][y] =
      min(dp[x][y], DP(x - 1, y - con[x][0] * x - con[x][1]) + con[x][0]);
  return dp[x][y];
}

int main() {
  for (int i = 0; i < 15; i++) {
    for (int j = 0; j < 1e5; i++) {
      dp[i][j] = -1;
    }
  }
  cin >> n >> goal;
  goal /= 100;
  for (int i = 1; i <= n; i++) {
    cin >> con[i][0] >> con[i][1];
    con[i][1] /= 100;
  }
  cout << DP(n, goal) << endl;
}

Fixed submission:
//
// Created by Huang,Zhiqiang on 2018/8/13.
//

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

const int INF = int(1e9);
int n, goal;
int con[15][2];
int dp[15][int(1e5)];

int DP(int x, int y) {
  if (y <= 0)
    return 0;
  if (x < 1)
    return INF;
  if (dp[x][y] != -1)
    return dp[x][y];
  dp[x][y] = INF;
  for (int i = 0; i < con[x][0]; i++)
    dp[x][y] = min(dp[x][y], DP(x - 1, y - i * x) + i);
  dp[x][y] =
      min(dp[x][y], DP(x - 1, y - con[x][0] * x - con[x][1]) + con[x][0]);
  return dp[x][y];
}

int main() {
  for (int i = 0; i < 15; i++) {
    for (int j = 0; j < 1e5; j++) {
      dp[i][j] = -1;
    }
  }
  cin >> n >> goal;
  goal /= 100;
  for (int i = 1; i <= n; i++) {
    cin >> con[i][0] >> con[i][1];
    con[i][1] /= 100;
  }
  cout << DP(n, goal) << endl;
}
Problem p03290 (C++)

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

int main() {
  int d, g;
  cin >> d >> g;
  vector<int> num(d), point(d);
  for (int i = 0; i < d; i++) {
    cin >> num.at(i) >> point.at(i);
  }

  int ans = 1e9;
  for (int check = 0; check < (1 << d); check++) {
    int sum = 0, count = 0, rest = -1;
    for (int i = 0; i < d; i++) {
      if (check >> i & 1) {
        sum += 100 * (i + 1) * num.at(i) * +point.at(i);
        count += num.at(i);
      } else {
        rest = i;
      }
    }
    if (sum < g) {
      int temp = 100 * (rest + 1);
      int need = (g - sum + temp - 1) / temp;
      if (need >= num.at(rest)) {
        continue;
      }
      count += need;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}


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

int main() {
  int d, g;
  cin >> d >> g;
  vector<int> num(d), point(d);
  for (int i = 0; i < d; i++) {
    cin >> num.at(i) >> point.at(i);
  }

  int ans = 1e9;
  for (int check = 0; check < (1 << d); check++) {
    int sum = 0, count = 0, rest = -1;
    for (int i = 0; i < d; i++) {
      if (check >> i & 1) {
        sum += 100 * (i + 1) * num.at(i) + point.at(i);
        count += num.at(i);
      } else {
        rest = i;
      }
    }
    if (sum < g) {
      int temp = 100 * (rest + 1);
      int need = (g - sum + temp - 1) / temp;
      if (need >= num.at(rest)) {
        continue;
      }
      count += need;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
struct r {
  int p, c;
} a[15];
int sum, dp[1050], d, g;
int main() {
  scanf("%d%d", &d, &g);
  for (int i = 1; i <= d; i++)
    scanf("%d%d", &a[i].p, &a[i].c), sum += a[i].p;
  for (int j = 1; j <= d; j++)
    for (int i = sum; i >= 1; i--) {
      if (i >= a[i].p)
        dp[i] = std::max(dp[i - a[j].p] + a[j].c + a[j].p * j * 100, dp[i]);
      for (int k = 1; k < a[j].p; k++)
        if (i >= k)
          dp[i] = std::max(dp[i - k] + k * j * 100, dp[i]);
    }
  for (int i = 1; i <= sum; i++)
    if (dp[i] >= g) {
      printf("%d\n", i);
      return 0;
    }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
struct r {
  int p, c;
} a[15];
int sum, dp[1050], d, g;
int main() {
  scanf("%d%d", &d, &g);
  for (int i = 1; i <= d; i++)
    scanf("%d%d", &a[i].p, &a[i].c), sum += a[i].p;
  for (int j = 1; j <= d; j++)
    for (int i = sum; i >= 1; i--) {
      if (i >= a[j].p)
        dp[i] = std::max(dp[i - a[j].p] + a[j].c + a[j].p * j * 100, dp[i]);
      for (int k = 1; k < a[j].p; k++)
        if (i >= k)
          dp[i] = std::max(dp[i - k] + k * j * 100, dp[i]);
    }
  for (int i = 1; i <= sum; i++)
    if (dp[i] >= g) {
      printf("%d\n", i);
      return 0;
    }
}
Problem p03290 (C++)

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

int d, g;
int p[105], c[105];
int res;

int cache[12][550005];

int foo(int now, int score) {
  if (now >= d) {
    if (score >= g)
      return 0;
    return 1e8;
  }
  if (score >= g)
    return 0;
  int &ret = cache[now][score];
  if (~ret)
    return ret;
  ret = 1e9;

  ret = foo(now + 1, score);

  for (int i = 0; i < p[now] - 1; i++) {
    int x = foo(now + 1, score + (i + 1) * (now + 1) * 100);
    ret = min(ret, x + i + 1);
  }

  ret = min(ret,
            p[now] + foo(now + 1, score + p[now] * (now + 1) * 100 + c[now]));
  return ret;
}

int main() {
  cin >> d >> g;
  for (int i = 0; i < d; ++i) {
    scanf("%d %d", &p[i], &c[i]);
  }

  memset(cache, -1, sizeof cache);
  res = 1e9;
  res = foo(0, 0);
  cout << res << endl;
}

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

int d, g;
int p[105], c[105];
int res;

int cache[12][10550005];

int foo(int now, int score) {
  if (now >= d) {
    if (score >= g)
      return 0;
    return 1e8;
  }
  if (score >= g)
    return 0;
  int &ret = cache[now][score];
  if (~ret)
    return ret;
  ret = 1e9;

  ret = foo(now + 1, score);

  for (int i = 0; i < p[now] - 1; i++) {
    int x = foo(now + 1, score + (i + 1) * (now + 1) * 100);
    ret = min(ret, x + i + 1);
  }

  ret = min(ret,
            p[now] + foo(now + 1, score + p[now] * (now + 1) * 100 + c[now]));
  return ret;
}

int main() {
  cin >> d >> g;
  for (int i = 0; i < d; ++i) {
    scanf("%d %d", &p[i], &c[i]);
  }

  memset(cache, -1, sizeof cache);
  res = 1e9;
  res = foo(0, 0);
  cout << res << endl;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int d, g;
  for (int i = 0; i < d; i++)
    cin >> d >> g;

  vector<ll> p(d);
  vector<ll> c(d);

  for (int i = 0; i < d; i++) {
    cin >> p.at(i) >> c.at(i);
  }

  ll res = 1 << 29;
  for (int bit = 0; bit < (1 << d); ++bit) {
    ll sum = 0;
    ll num = 0;
    for (int i = 0; i < d; ++i) {
      if (bit & (1 << i))
        sum += c[i] + p[i] * 100 * (i + 1), num += p[i];
    }
    if (sum >= g)
      res = min(res, num);
    else {
      for (int i = d - 1; i >= 0; --i) {
        if (bit & (1 << i))
          continue;
        for (int j = 0; j < p[i]; ++j) {
          if (sum >= g)
            break;
          sum += 100 * (i + 1);
          ++num;
        }
      }
      res = min(res, num);
    }
  }
  cout << res << endl;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int d, g;
  cin >> d >> g;

  vector<ll> p(d);
  vector<ll> c(d);

  for (int i = 0; i < d; i++) {
    cin >> p.at(i) >> c.at(i);
  }

  ll res = 1 << 29;
  for (int bit = 0; bit < (1 << d); ++bit) {
    ll sum = 0;
    ll num = 0;
    for (int i = 0; i < d; ++i) {
      if (bit & (1 << i))
        sum += c[i] + p[i] * 100 * (i + 1), num += p[i];
    }
    if (sum >= g)
      res = min(res, num);
    else {
      for (int i = d - 1; i >= 0; --i) {
        if (bit & (1 << i))
          continue;
        for (int j = 0; j < p[i]; ++j) {
          if (sum >= g)
            break;
          sum += 100 * (i + 1);
          ++num;
        }
      }
      res = min(res, num);
    }
  }
  cout << res << endl;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define lp(i, n) for (int i = 0; i < (int)n; ++i)
#define read(n) scanf("%d", &n)
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, g;
int p[N], c[101][101], dp[101][N];
int solve(int idx, int sm) {
  if (sm >= g)
    return 0;
  if (idx > n)
    return 1e9;
  int &ret = dp[idx][sm];
  if (ret != -1)
    return ret;
  ret = 1e9;
  for (int i = 1; i <= p[idx]; i++) {
    ret = min(ret, solve(idx + 1, sm + ((idx * 100 * i) + c[idx][i])) + i);
    ret = min(ret, solve(idx + 1, sm));
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &g);
  lp(i, 101) lp(j, N) dp[i][j] = -1;
  lp(i, n) {
    scanf("%d", &p[i + 1]);
    scanf("%d", &c[i + 1][p[i + 1]]);
  }
  printf("%d", solve(1, 0));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define lp(i, n) for (int i = 0; i < (int)n; ++i)
#define read(n) scanf("%d", &n)
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int n, g;
int p[N], c[101][101], dp[101][N];
int solve(int idx, int sm) {
  if (sm >= g)
    return 0;
  if (idx > n)
    return 1e9;
  int &ret = dp[idx][sm];
  if (ret != -1)
    return ret;
  ret = 1e9;
  for (int i = 1; i <= p[idx]; i++) {
    ret = min(ret, solve(idx + 1, sm + ((idx * 100 * i) + c[idx][i])) + i);
    ret = min(ret, solve(idx + 1, sm));
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &g);
  lp(i, 101) lp(j, N) dp[i][j] = -1;
  lp(i, n) {
    scanf("%d", &p[i + 1]);
    scanf("%d", &c[i + 1][p[i + 1]]);
  }
  printf("%d", solve(1, 0));
  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
using namespace std;
typedef long long ll;

int main() {
  int d, g, p[11], c[11];
  cin >> d >> g;
  REP(i, d) cin >> p[i] >> c[i];

  int ans = 1e9;
  REP(bit, (1 << d)) {
    int s = 0, num = 0, rest = -1;
    REP(i, d) {
      if (bit >> i & 1) {
        s = 100 * (i + 1) * p[i] + c[i];
        num += p[i];
      } else {
        rest = i;
      }
    }
    if (s < g) {
      int s1 = 100 * (rest + 1);
      int need = (g - s + s1 - 1) / s1;
      if (need >= p[rest])
        continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int64_t i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
using namespace std;
typedef long long ll;

int main() {
  int d, g, p[11], c[11];
  cin >> d >> g;
  REP(i, d) cin >> p[i] >> c[i];

  int ans = 1e9;
  REP(bit, (1 << d)) {
    int s = 0, num = 0, rest = -1;
    REP(i, d) {
      if (bit >> i & 1) {
        s += 100 * (i + 1) * p[i] + c[i];
        num += p[i];
      } else {
        rest = i;
      }
    }
    if (s < g) {
      int s1 = 100 * (rest + 1);
      int need = (g - s + s1 - 1) / s1;
      if (need >= p[rest])
        continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}
Problem p03290 (C++)

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

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

  int D, G;
  cin >> D >> G;
  vector<int> p(D - 1);
  vector<int> c(D - 1);
  rep(i, D) cin >> p[i] >> c[i];

  int res = 1e9;

  rep(mask, 1 << D) {
    int score = 0; // All or nothing
    int numSolved = 0, maxRestP = -1;

    rep(i, D) {
      if (mask & 1 << i) {
        score += 100 * (i + 1) * p[i] + c[i];
        numSolved += p[i];
      } else
        maxRestP = i;
    }

    if (score < G) {
      int scoreMaxRestP = 100 * (maxRestP + 1);
      int numNeeded = (G - score + scoreMaxRestP - 1) / scoreMaxRestP;
      if (numNeeded >= p[maxRestP])
        continue;
      numSolved += numNeeded;
    }

    res = min(res, numSolved);
  }

  cout << res << "\n";
}

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

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

  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  rep(i, D) cin >> p[i] >> c[i];

  int res = 1e9;

  rep(mask, 1 << D) {
    int score = 0; // All or nothing
    int numSolved = 0, maxRestP = -1;

    rep(i, D) {
      if (mask & 1 << i) {
        score += 100 * (i + 1) * p[i] + c[i];
        numSolved += p[i];
      } else
        maxRestP = i;
    }

    if (score < G) {
      int scoreMaxRestP = 100 * (maxRestP + 1);
      int numNeeded = (G - score + scoreMaxRestP - 1) / scoreMaxRestP;
      if (numNeeded >= p[maxRestP])
        continue;
      numSolved += numNeeded;
    }

    res = min(res, numSolved);
  }

  cout << res << "\n";
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define REP(i, n) for (ll i = 0; i < n; i++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;

ll D, G;
ll p[10];
ll c[10];

int main() {
  cin >> D >> G;
  REP(i, D) cin >> p[i] >> c[i];

  ll ans = 1e18;
  REP(i, (1 << D)) {
    ll sumG = 0;
    ll sump = 0;
    ll left_p[10];
    REP(j, D) left_p[j] = p[j];
    REP(j, D) {
      if ((i >> j) & 1) {
        sumG += 100LL * (j + 1LL) * p[j] + c[j];
        sump += p[j];
        left_p[j] = 0;
      }
    }
    vector<ll> lt;
    REP(j, D) REP(k, left_p[j]) lt.push_back(100LL * (j + 1LL));
    sort(lt.begin(), lt.end());
    reverse(lt.begin(), lt.end());
    int cnt = 0;
    while (sumG < G) {
      sumG += lt[cnt++];
      sump++;
    }
    ans = min(ans, sump);
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define REP(i, n) for (ll i = 0; i < n; i++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;

ll D, G;
ll p[10];
ll c[10];

int main() {
  cin >> D >> G;
  REP(i, D) cin >> p[i] >> c[i];

  ll ans = 1e18;
  REP(i, (1 << D)) {
    ll sumG = 0;
    ll sump = 0;
    ll left_p[10];
    REP(j, D) left_p[j] = p[j];
    REP(j, D) {
      if ((i >> j) & 1) {
        sumG += 100LL * (j + 1LL) * p[j] + c[j];
        sump += p[j];
        left_p[j] = 0;
      }
    }
    vector<ll> lt;
    REP(j, D) REP(k, left_p[j]) lt.push_back(100LL * (j + 1LL));
    sort(lt.begin(), lt.end());
    reverse(lt.begin(), lt.end());
    int cnt = 0;
    while (sumG < G) {
      sumG += lt[cnt];
      ll idx = (lt[cnt] / 100LL) - 1LL;
      left_p[idx]--;
      if (left_p[idx] == 0)
        sumG += c[idx];
      cnt++;
      sump++;
    }
    ans = min(ans, sump);
  }

  cout << ans << endl;

  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int maxN = 10000 + 10;
long long p[maxN], c[maxN];
long long dp[maxN][maxN];

int main() {
  int d, g;
  cin >> d >> g;
  int tmp = 0;
  for (int i = 1; i <= d; i++) {
    cin >> p[i] >> c[i];
    tmp += p[i];
  }
  int res = -1;
  for (int a = 0; a <= tmp; a++) {
    memset(dp, 0, sizeof(dp));

    for (int i = 1; i <= d; i++) {
      for (int j = 1; j <= a; j++) {
        for (int k = 0; j - k >= 0 && k <= p[i]; k++) {
          if (k == p[i])
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - k] + k * i * 100 + c[i]);
          else
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - k] + k * i * 100);
        }
      }
    }
    // cout<<dp[d][a]<<endl;
    if (dp[d][a] >= g) {
      res = a;
      break;
    }
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int maxN = 1000 + 100;
long long p[maxN], c[maxN];
long long dp[maxN][maxN];

int main() {
  int d, g;
  cin >> d >> g;
  int tmp = 0;
  for (int i = 1; i <= d; i++) {
    cin >> p[i] >> c[i];
    tmp += p[i];
  }
  int res = -1;
  for (int a = 0; a <= tmp; a++) {
    memset(dp, 0, sizeof(dp));

    for (int i = 1; i <= d; i++) {
      for (int j = 1; j <= a; j++) {
        for (int k = 0; j - k >= 0 && k <= p[i]; k++) {
          if (k == p[i])
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - k] + k * i * 100 + c[i]);
          else
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - k] + k * i * 100);
        }
      }
    }
    // cout<<dp[d][a]<<endl;
    if (dp[d][a] >= g) {
      res = a;
      break;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03290 (C++)

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

int main() {
  int D, G;
  cin >> D >> G;
  G /= 100;

  vector<int> p(D), c(D);
  vector<int> CompletePoint(D);
  int NumLeast = 0;
  for (int i = 0; i < D; i++) {
    cin >> p.at(i) >> c.at(i);
    CompletePoint.at(i) = (p.at(i) * (i + 1) + c.at(i) / 100);
    NumLeast += p.at(i);
  }

  for (int i = 0; i < (1 << (D)); i++) {
    bitset<9> tmp(i);
    int Point = 0;
    int Num = 0;
    int id = 0;
    for (int j = 0; j < (D); j++) {
      if (tmp.test(j)) {
        Point += CompletePoint.at(j);
        Num += p.at(j);
      } else {
        id = j;
      }
    }

    if (G - Point <= 0) {
      if (NumLeast > Num) {
        NumLeast = Num;
      }
    } else if (G - Point <= (id + 1) * (p.at(id) - 1)) {
      if ((G - Point) % (id + 1) == 0) {
        Num += (G - Point) / (id + 1);
      } else {
        Num += ((G - Point) / (id + 1) + 1);
      }
      if (NumLeast > Num) {
        NumLeast = Num;
      }
    }
  }
  cout << NumLeast;
}

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

int main() {
  int D, G;
  cin >> D >> G;
  G /= 100;

  vector<int> p(D), c(D);
  vector<int> CompletePoint(D);
  int NumLeast = 0;
  for (int i = 0; i < D; i++) {
    cin >> p.at(i) >> c.at(i);
    CompletePoint.at(i) = (p.at(i) * (i + 1) + c.at(i) / 100);
    NumLeast += p.at(i);
  }

  for (int i = 0; i < (1 << (D)); i++) {
    bitset<10> tmp(i);
    int Point = 0;
    int Num = 0;
    int id = 0;
    for (int j = 0; j < (D); j++) {
      if (tmp.test(j)) {
        Point += CompletePoint.at(j);
        Num += p.at(j);
      } else {
        id = j;
      }
    }

    if (G - Point <= 0) {
      if (NumLeast > Num) {
        NumLeast = Num;
      }
    } else if (G - Point <= (id + 1) * (p.at(id) - 1)) {
      if ((G - Point) % (id + 1) == 0) {
        Num += (G - Point) / (id + 1);
      } else {
        Num += ((G - Point) / (id + 1) + 1);
      }
      if (NumLeast > Num) {
        NumLeast = Num;
      }
    }
  }
  cout << NumLeast;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
// #include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

void solve() {
  int d, g;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
  }
  int res = 10000;
  for (int i = 0; i < (1 << d); i++) {
    vector<int> pm(3000);
    ll sum = 0;
    int ct = 0;
    for (int j = 0; j < d; j++)
      if ((1 & (i >> j))) {
        ct += p[j];
        sum += c[j];
        sum += 100 * (j + 1) * p[j];
      } else
        for (int k = 0; k < p[j]; k++)
          pm.push_back(100 * (j + 1));
    sort(pm.begin(), pm.end());
    int index = pm.size() - 1;
    while (sum < g) {
      ct++;
      sum += pm[index--];
    }
    res = min(res, ct);
  }
  cout << res << endl;
}

int main() {
  solve();
  return 0;
}


Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

void solve() {
  int d, g;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
  }
  int res = 10000;
  for (int i = 0; i < (1 << d); i++) {
    vector<int> pm(3000);
    ll sum = 0;
    int ct = 0;
    for (int j = 0; j < d; j++)
      if ((1 & (i >> j))) {
        ct += p[j];
        sum += c[j];
        sum += 100 * (j + 1) * p[j];
      } else
        for (int k = 0; k < p[j]; k++)
          pm.push_back(100 * (j + 1));
    sort(pm.begin(), pm.end());
    int index = pm.size() - 1;
    while (index != -1 && sum < g) {
      ct++;
      sum += pm[index--];
    }
    res = min(res, ct);
  }
  cout << res << endl;
}

int main() {
  solve();
  return 0;
}
Problem p03290 (C++)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 50;
const ll oo = 1e18;
const ll mod = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  int a[10];
  for (int i = 0; i < 10; i++)
    a[i] = i;
  int mn = 1e9;
  do {
    int need = m;
    int S = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < v[a[i]].first; j++) {
        if (need > 0) {
          need -= ((a[i] + 1) * 100);
          S++;
        } else {
          break;
        }
        if (j == v[a[i]].first - 1)
          need -= (v[a[i]].second);
      }
      if (need <= 0)
        break;
    }
    mn = min(mn, S);
  } while (next_permutation(a, a + n));
  cout << mn << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 50;
const ll oo = 1e18;
const ll mod = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  int a[10];
  for (int i = 0; i < 10; i++)
    a[i] = i;
  int mn = 1e9;
  do {
    int need = m;
    int S = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < v[a[i]].first; j++) {
        if (need - (ll((a[i] + 1) * 100) * ll(v[a[i]].first)) > 0) {
          need -= (ll((a[i] + 1) * 100) * ll(v[a[i]].first));
          S += v[a[i]].first;
          need -= v[a[i]].second;
          break;
        }
        if (need > 0) {
          need -= ((a[i] + 1) * 100);
          S++;
        } else {
          break;
        }
        if (j == v[a[i]].first - 1)
          need -= (v[a[i]].second);
      }
      if (need <= 0)
        break;
    }
    mn = min(mn, S);
  } while (next_permutation(a, a + n));
  cout << mn << endl;
  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 10000000;

int dp[11][200001];

const int lim = 100000;

int main() {
  int D, G;
  cin >> D >> G;
  G /= 100;
  int p[D], c[D];
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  for (int i = 0; i <= D; i++) {
    for (int j = 0; j < 200001; j++) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < D; i++) {
    for (int k = 0; k <= lim; k++)
      dp[i + 1][k] = dp[i][k];
    int tp = p[i];
    for (int j = 0; tp > 0; j++) {
      int key = min(tp, 1 << j);
      tp -= key;
      for (int k = lim; k >= 0; k--) {
        dp[i + 1][k + (i + 1) * key] =
            min(dp[i + 1][k + (i + 1) * key], dp[i + 1][k] + key);
      }
    }
    for (int k = 2 * lim; k >= 0; k--) {
      if (dp[i + 1][k + p[i] * (i + 1)] - dp[i][k] == p[i])
        dp[i + 1][k + p[i] * (i + 1) + c[i]] =
            min(dp[i + 1][k + p[i] * (i + 1) + c[i]],
                dp[i + 1][k + p[i] * (i + 1)]);
    }
  }
  int ans = INF;
  for (int k = G; k < 2 * lim; k++)
    ans = min(ans, dp[D][k]);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 10000000;

int dp[11][200001];

const int lim = 100000;

int main() {
  int D, G;
  cin >> D >> G;
  G /= 100;
  int p[D], c[D];
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  for (int i = 0; i <= D; i++) {
    for (int j = 0; j < 200001; j++) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < D; i++) {
    for (int k = 0; k <= lim; k++)
      dp[i + 1][k] = dp[i][k];
    int tp = p[i];
    for (int j = 0; tp > 0; j++) {
      int key = min(tp, 1 << j);
      tp -= key;
      for (int k = lim; k >= 0; k--) {
        dp[i + 1][k + (i + 1) * key] =
            min(dp[i + 1][k + (i + 1) * key], dp[i + 1][k] + key);
      }
    }
    for (int k = 0; k < lim; k++) {
      dp[i + 1][k + p[i] * (i + 1) + c[i]] =
          min(dp[i + 1][k + p[i] * (i + 1) + c[i]], dp[i][k] + p[i]);
    }
  }
  int ans = INF;
  for (int k = G; k < 2 * lim; k++)
    ans = min(ans, dp[D][k]);
  cout << ans << endl;
  return 0;
}
Problem p03290 (C++)

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

#define llong long long
#define ii pair<int, int>
#define fir first
#define sec second
#define len(x) ((int)x.size())
#define rep(i, n) for (int i = -1; ++i < (n);)
#define rep1(i, n) for (int i = 0; i++ < (n);)

template <typename t> /*{{{*/
ostream &operator<<(ostream &cout, const vector<t> &a) {
  cout << "[";
  rep(i, len(a)) cout << a[i] << ", ";
  return cout << "]";
}

template <typename u, typename v>
ostream &operator<<(ostream &cout, const pair<u, v> &t) {
  return cout << "(" << t.fir << ", " << t.sec << ")";
} /*}}}*/

#define maxg 6000
#define maxd 20
#define inf 10101010
int d, g;
int dp[maxd][maxg] = {0};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> d >> g;
  g /= 100;
  rep(i, d + 1) rep(f, g + 1) dp[i][f] = inf;
  dp[0][0] = 0;
  rep1(i, d) {
    int u, v;
    cin >> u >> v;
    v /= 100;
    rep(f, 1 + u) {
      int ad = i * f + (f == u ? v : 0);
      rep(h, g + 1) dp[i][min(h + ad, g)] =
          min(dp[i][min(h + ad, g)], dp[i - 1][h] + f);
    }
  }
  cout << dp[d][g];

  return 0;
}


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

#define llong long long
#define ii pair<int, int>
#define fir first
#define sec second
#define len(x) ((int)x.size())
#define rep(i, n) for (int i = -1; ++i < (n);)
#define rep1(i, n) for (int i = 0; i++ < (n);)

template <typename t> /*{{{*/
ostream &operator<<(ostream &cout, const vector<t> &a) {
  cout << "[";
  rep(i, len(a)) cout << a[i] << ", ";
  return cout << "]";
}

template <typename u, typename v>
ostream &operator<<(ostream &cout, const pair<u, v> &t) {
  return cout << "(" << t.fir << ", " << t.sec << ")";
} /*}}}*/

#define maxg 600000
#define maxd 20
#define inf 10101010
int d, g;
int dp[maxd][maxg] = {0};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> d >> g;
  g /= 100;
  rep(i, d + 1) rep(f, g + 1) dp[i][f] = inf;
  dp[0][0] = 0;
  rep1(i, d) {
    int u, v;
    cin >> u >> v;
    v /= 100;
    rep(f, 1 + u) {
      int ad = i * f + (f == u ? v : 0);
      rep(h, g + 1) dp[i][min(h + ad, g)] =
          min(dp[i][min(h + ad, g)], dp[i - 1][h] + f);
    }
  }
  cout << dp[d][g];

  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int main() {
  int d, g;
  int i, j;
  int p[11], c[11];
  scanf("%d%d", &d, &g);
  for (i = 0; i < d; i++)
    scanf("%d%d", &p[i], &c[i]);
  int ans = INF;
  for (i = 0; i < (1 << d); i++) {
    ll sum = 0;
    int ss = 0;
    for (j = 0; j < d; j++) {
      if ((i >> j) & 1) {
        sum += p[j] * (j + 1) * 100 + c[i];
        ss += p[j];
      }
    }
    for (j = d - 1; j >= 0; j--) {
      if ((i >> j) & 1)
        continue;
      if (sum >= g)
        continue;
      int s;
      s = (g - sum) / ((j + 1) * 100);
      s = min(s, p[j]);
      ss += s;
      sum += (j + 1) * 100 * s;
    }
    if (g <= sum)
      ans = min(ans, ss);
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int main() {
  int d, g;
  int i, j;
  int p[11], c[11];
  scanf("%d%d", &d, &g);
  for (i = 0; i < d; i++)
    scanf("%d%d", &p[i], &c[i]);
  int ans = INF;
  for (i = 0; i < (1 << d); i++) {
    ll sum = 0;
    int ss = 0;
    for (j = 0; j < d; j++) {
      if ((i >> j) & 1) {
        sum += p[j] * (j + 1) * 100 + c[j];
        ss += p[j];
      }
    }
    for (j = d - 1; j >= 0; j--) {
      if ((i >> j) & 1)
        continue;
      if (sum >= g)
        continue;
      int s;
      s = (g - sum) / ((j + 1) * 100);
      s = min(s, p[j]);
      ss += s;
      sum += (j + 1) * 100 * s;
    }
    if (g <= sum)
      ans = min(ans, ss);
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n;
long long INF = 200000;
long long dp[11][150005];
int bonus[11];
int p[11];
long long f(int curr, int score) {
  if (score <= 0)
    return 0;
  long long &ret = dp[curr][score];
  if (~ret)
    return ret;
  if (curr > n)
    return ret = INF;
  ret = INF;
  for (int i = 0; i < p[curr]; i++) {
    ret = min(ret, i + f(curr + 1, score - i * curr));
  }
  ret = min(ret, p[curr] + f(curr + 1, score - curr * p[curr] - bonus[curr]));
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int g;
  cin >> n >> g;
  g /= 100;
  for (int i = 1; i <= n; i++) {
    cin >> p[i] >> bonus[i];
    bonus[i] /= 100;
  }
  cout << f(1, g);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n;
long long INF = 200000;
long long dp[20][200000];
int bonus[20];
int p[20];
long long f(int curr, int score) {
  if (score <= 0)
    return 0;
  long long &ret = dp[curr][score];
  if (~ret)
    return ret;
  if (curr > n)
    return ret = INF;
  ret = INF;
  for (int i = 0; i < p[curr]; i++) {
    ret = min(ret, i + f(curr + 1, score - i * curr));
  }
  ret = min(ret, p[curr] + f(curr + 1, score - curr * p[curr] - bonus[curr]));
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  int g;
  cin >> n >> g;
  g /= 100;
  for (int i = 1; i <= n; i++) {
    cin >> p[i] >> bonus[i];
    bonus[i] /= 100;
  }
  cout << f(1, g);
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m;
struct qq {
  int p, c;
} s[15];
int f[1000005];
int sum = 0;
int main() {
  scanf("%d%d", &n, &m);
  m /= 100;

  memset(f, 63, sizeof(f));
  f[0] = 0;
  for (int u = 1; u <= n; u++) {
    scanf("%d%d", &s[u].p, &s[u].c);
    s[u].c /= 100;
    sum = sum + s[u].p * u + s[u].c;
  }
  for (int u = 1; u <= n; u++)
    for (int i = sum; i >= 0; i--) {
      if (i >= u * s[u].p - s[u].c)
        f[i] = min(f[i], f[i - u * s[u].p - s[u].c] + s[u].p);
      for (int j = 1; j < s[u].p; j++) {
        //	if (i==2) printf("YES%d %d\n",j,i-u*j);
        if (i >= u * j)
          f[i] = min(f[i], f[i - u * j] + j);
      }
      //	printf("%d %d %d\n",i,f[i],u*s[u].p+s[u].c);
    }
  int ans = f[m];
  for (int u = m + 1; u <= sum; u++)
    ans = min(ans, f[u]);
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m;
struct qq {
  int p, c;
} s[15];
int f[1000005];
int sum = 0;
int main() {
  scanf("%d%d", &n, &m);
  m /= 100;

  memset(f, 63, sizeof(f));
  f[0] = 0;
  for (int u = 1; u <= n; u++) {
    scanf("%d%d", &s[u].p, &s[u].c);
    s[u].c /= 100;
    sum = sum + s[u].p * u + s[u].c;
  }
  for (int u = 1; u <= n; u++)
    for (int i = sum; i >= 0; i--) {
      if (i >= u * s[u].p + s[u].c)
        f[i] = min(f[i], f[i - u * s[u].p - s[u].c] + s[u].p);
      for (int j = 1; j < s[u].p; j++) {
        //	if (i==2) printf("YES%d %d\n",j,i-u*j);
        if (i >= u * j)
          f[i] = min(f[i], f[i - u * j] + j);
      }
      //	printf("%d %d %d\n",i,f[i],u*s[u].p+s[u].c);
    }
  int ans = f[m];
  for (int u = m + 1; u <= sum; u++)
    ans = min(ans, f[u]);
  printf("%d\n", ans);
  return 0;
}
Problem p03290 (C++)

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

int main() {
  int D, G, ans = 1e9;
  cin >> D >> G;
  vector<int> p, c;

  for (int i = 0; i < D; ++i) {
    cin >> p[i] >> c[i];
  }

  for (int mask = 0; mask < (1 << D); ++mask) {
    int s = 0, num = 0, rest_max = -1;
    for (int i = 0; i < D; ++i) {
      if (mask >> i & 1) {
        s += 100 * (i + 1) * p[i] + c[i];
        num += p[i];
      } else {
        rest_max = i;
      }
    }
    if (s < G) {
      int s1 = 100 * (rest_max + 1);
      int need = (G - s + s1 - 1) / s1;
      if (need >= p[rest_max]) {
        continue;
      }
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

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

int main() {
  int D, G, ans = 1e9;
  cin >> D >> G;
  vector<int> p(D), c(D);

  for (int i = 0; i < D; ++i) {
    cin >> p[i] >> c[i];
  }

  for (int mask = 0; mask < (1 << D); ++mask) {
    int s = 0, num = 0, rest_max = -1;
    for (int i = 0; i < D; ++i) {
      if (mask >> i & 1) {
        s += 100 * (i + 1) * p[i] + c[i];
        num += p[i];
      } else {
        rest_max = i;
      }
    }
    if (s < G) {
      int s1 = 100 * (rest_max + 1);
      int need = (G - s + s1 - 1) / s1;
      if (need >= p[rest_max]) {
        continue;
      }
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.14159265358979;
const ll INF = pow(10, 18);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll D, G;
  cin >> D >> G;
  vl p(D), c(D);
  rep(i, D) { cin >> p[i] >> c[i]; }
  vvl dp(
      D,
      vl(D * 100,
         -INF)); // dp[i][j]で、(i+1)*100点文台以上で計j問解いた時の得点の最大値とする。
  rep(i, p[D - 1]) { dp[D - 1][i] = 100 * D * i; }
  ll sumP = p[D - 1];
  dp[D - 1][p[D - 1]] = 100 * D * p[D - 1] + c[D - 1];
  for (ll i = D - 2; i >= 0; i--) {
    sumP += p[i];
    rep(j, sumP + 1) {
      if (j <= sumP - p[i]) {
        dp[i][j] = dp[i + 1][j];
      } else {
        dp[i][j] = dp[i + 1][sumP - p[i]] + 100 * (i + 1) * (j - sumP + p[i]);
      }
      if (j >= p[i]) {
        dp[i][j] =
            max(dp[i][j], dp[i + 1][j - p[i]] + p[i] * (i + 1) * 100 + c[i]);
      } else if (sumP - p[i] < j && j < p[i]) {
        dp[i][j] = max(dp[i][j], dp[i + 1][sumP - p[i]] +
                                     (j - sumP + p[i]) * (i + 1) * 100);
      }
    }
  }
  ll i = 0;
  cout << dp[4][1] << endl;
  while (dp[0][i] < G) {
    i++;
  }
  cout << i << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.14159265358979;
const ll INF = pow(10, 18);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll D, G;
  cin >> D >> G;
  vl p(D), c(D);
  rep(i, D) { cin >> p[i] >> c[i]; }
  vvl dp(
      D,
      vl(D * 100,
         -INF)); // dp[i][j]で、(i+1)*100点文台以上で計j問解いた時の得点の最大値とする。
  rep(i, p[D - 1]) { dp[D - 1][i] = 100 * D * i; }
  ll sumP = p[D - 1];
  dp[D - 1][p[D - 1]] = 100 * D * p[D - 1] + c[D - 1];
  for (ll i = D - 2; i >= 0; i--) {
    sumP += p[i];
    rep(j, sumP + 1) {
      if (j <= sumP - p[i]) {
        dp[i][j] = dp[i + 1][j];
      } else {
        dp[i][j] = dp[i + 1][sumP - p[i]] + 100 * (i + 1) * (j - sumP + p[i]);
      }
      if (j >= p[i]) {
        dp[i][j] =
            max(dp[i][j], dp[i + 1][j - p[i]] + p[i] * (i + 1) * 100 + c[i]);
      } else if (sumP - p[i] < j && j < p[i]) {
        dp[i][j] = max(dp[i][j], dp[i + 1][sumP - p[i]] +
                                     (j - sumP + p[i]) * (i + 1) * 100);
      }
    }
  }
  ll i = 0;
  while (dp[0][i] < G) {
    i++;
  }
  cout << i << endl;
}
Problem p03290 (C++)

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

int a[111], b[111];

int d, g;

int dp[11][2 * 1111111];
int check(int i, int sum) {

  if (sum <= 0)
    return 0;
  if (i > d)
    return 10000;
  if (~dp[i][sum])
    return dp[i][sum];
  int res = INT_MAX, r;

  for (int j = 0; j <= a[i]; j++) {
    r = 100 * j * i;
    if (j == a[i])
      r += b[i];

    res = min(res, j + check(i + 1, sum - r));
  }
  return dp[i][sum] = res;
}

int main() {

  cin >> d >> g;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= d; i++)
    cin >> a[i] >> b[i];

  cout << check(1, g) << endl;
}


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

int a[111], b[111];

int d, g;

int dp[11][2 * 11111111];
int check(int i, int sum) {

  if (sum <= 0)
    return 0;
  if (i > d)
    return 10000;
  if (~dp[i][sum])
    return dp[i][sum];
  int res = INT_MAX, r;

  for (int j = 0; j <= a[i]; j++) {
    r = 100 * j * i;
    if (j == a[i])
      r += b[i];

    res = min(res, j + check(i + 1, sum - r));
  }
  return dp[i][sum] = res;
}

int main() {

  cin >> d >> g;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= d; i++)
    cin >> a[i] >> b[i];

  cout << check(1, g) << endl;
}
Problem p03290 (C++)

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

int main() {
  int D, G;
  cin >> D >> G;
  vector<vector<int>> v(D, vector<int>(3));
  for (int i = 0; i < D; i++) {
    cin >> v.at(i).at(0) >> v.at(i).at(1);
    v.at(i).at(2) = 100 * (i + 1) * v.at(i).at(0) + v.at(i).at(1);
  }
  int ans = 1000;
  for (int bit = 0; bit < (1 << D); bit++) {
    int sum = 0, count = 0, rest_max = -1;
    for (int i = 0; i < D; i++) {
      if (bit & (1 << i)) {
        sum += v.at(i).at(2);
        count += v.at(i).at(0);
      } else {
        rest_max = i;
      }
      if (sum < G) {
        int s = 100 * (rest_max + 1);
        int need = (G - sum + s - 1) / s;
        if (need < v.at(i).at(0)) {
          count += need;
          break;
        }
      }
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

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

int main() {
  int D, G;
  cin >> D >> G;
  vector<vector<int>> v(D, vector<int>(3));
  for (int i = 0; i < D; i++) {
    cin >> v.at(i).at(0) >> v.at(i).at(1);
    v.at(i).at(2) = 100 * (i + 1) * v.at(i).at(0) + v.at(i).at(1);
  }
  int ans = 1000;
  for (int bit = 0; bit < (1 << D); bit++) {
    int sum = 0, count = 0, rest_max = -1;
    for (int i = 0; i < D; i++) {
      if (bit & (1 << i)) {
        sum += v.at(i).at(2);
        count += v.at(i).at(0);
      } else {
        rest_max = i;
      }
    }
    if (sum < G) {
      int s = 100 * (rest_max + 1);
      int need = (G - sum + s - 1) / s;
      if (need < v.at(rest_max).at(0)) {
        count += need;
      } else {
        continue;
      }
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}