prithivMLmods/Coder-Stat huggingface dataset:
Problem p03288 (Python)

Buggy submission (status: Runtime Error):
r = int(input())
if 0 <= r and r < 1200:
    print("ABC")
elif 1200 <= r and r < 2800:
    print("ARC")
elif 2800 <= r and r < 4208:
    print("AGC")
else:
    raise ValueError


Fixed submission:
r = int(input())
if 0 <= r and r < 1200:
    print("ABC")
elif 1200 <= r and r < 2800:
    print("ARC")
elif 2800 <= r and r <= 4208:
    print("AGC")
else:
    raise ValueError
Problem p03288 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main(void) {
  int R;
  do {
    scanf("%d", &R);
  } while (R <= 0 || R >= 4208);

  if (R < 1200)
    printf("ABC\n");

  else if (R < 2800)
    printf("ARC\n");

  else
    printf("AGC\n");

  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int R;
  do {
    scanf("%d", &R);
  } while (R <= 0 && R >= 4208);

  if (R < 1200)
    printf("ABC\n");

  else if (R < 2800)
    printf("ARC\n");

  else
    printf("AGC\n");

  return 0;
}
Problem p03288 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int n;
  while (scanf("%d", &n))

  {
    if (n < 1200)
      printf("ABC\n");
    else if (n < 2800)
      printf("ARC\n");
    else
      printf("AGC\n");
  }
}

Fixed submission:
#include <stdio.h>
int main() {
  int n;
  while (scanf("%d", &n) != EOF)

  {
    if (n < 1200)
      printf("ABC\n");
    else if (n < 2800)
      printf("ARC\n");
    else
      printf("AGC\n");
  }
}
Problem p03288 (C++)

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define inf (long long int)1e18
#define vi vector<ll>
#define pii pair<ll, ll>
#define mii map<ll, ll>
#define mod 1000000007

ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  if (a == b)
    return a;
  if (a > b)
    return gcd(a % b, b);
  return gcd(a, b % a);
}

ll palindrome(string s) {
  ll l = 0;
  ll h = s.length() - 1;
  while (h > l) {
    if (s[l++] != s[h--]) {
      return 0;
    }
  }
  return 1;
}

ll modexp(ll a, ll b, ll m) {
  if (b == 0)
    return 1;
  ll temp = modexp(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b & 1)
    return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
  return temp;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int r;
  cin >> r;
  if (r < 1200)
    cout << "ABC" << endl;
  else if (r >= 1200 && r < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
}


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

#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define inf (long long int)1e18
#define vi vector<ll>
#define pii pair<ll, ll>
#define mii map<ll, ll>
#define mod 1000000007

ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  if (a == b)
    return a;
  if (a > b)
    return gcd(a % b, b);
  return gcd(a, b % a);
}

ll palindrome(string s) {
  ll l = 0;
  ll h = s.length() - 1;
  while (h > l) {
    if (s[l++] != s[h--]) {
      return 0;
    }
  }
  return 1;
}

ll modexp(ll a, ll b, ll m) {
  if (b == 0)
    return 1;
  ll temp = modexp(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b & 1)
    return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
  return temp;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  /*#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif*/

  int r;
  cin >> r;
  if (r < 1200)
    cout << "ABC" << endl;
  else if (r >= 1200 && r < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
}
Problem p03288 (Python)

Buggy submission (status: Runtime Error):
r = input()
if r < 1200:
    print("ABC")
elif 1200 <= r < 2800:
    print("ARC")
else:
    print("AGC")


Fixed submission:
r = int(input())
if r < 1200:
    print("ABC")
elif 1200 <= r < 2800:
    print("ARC")
else:
    print("AGC")
Problem p03288 (Python)

Buggy submission (status: Runtime Error):
r = input()

if r < 1200:
    print("ABC")
elif r < 2800:
    print("ARC")
else:
    print("AGC")


Fixed submission:
r = int(input())

if r < 1200:
    print("ABC")
elif r < 2800:
    print("ARC")
else:
    print("AGC")
Problem p03289 (C++)

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

void wa() {
  cout << "WA" << endl;
  exit(1);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s;
  cin >> s;
  int n = s.size();
  if (s[0] != 'A')
    wa();
  int cnt = 0;
  for (int i = 2; i < n - 1; i++) {
    cnt += s[i] == 'C';
  }
  if (cnt != 1)
    wa();
  for (int i = 1; i < n; i++) {
    if (s[i] == 'C')
      continue;
    if ('A' <= s[i] && s[i] <= 'Z')
      wa();
  }
  cout << "AC" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

void wa() {
  cout << "WA" << endl;
  exit(0);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s;
  cin >> s;
  int n = s.size();
  if (s[0] != 'A')
    wa();
  int cnt = 0;
  for (int i = 2; i < n - 1; i++) {
    cnt += s[i] == 'C';
  }
  if (cnt != 1)
    wa();
  for (int i = 1; i < n; i++) {
    if (s[i] == 'C')
      continue;
    if ('A' <= s[i] && s[i] <= 'Z')
      wa();
  }
  cout << "AC" << endl;

  return 0;
}
Problem p03289 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

int main() {

  std::string s;
  std::cin >> s;

  if (s.substr(0, 1) != "A") {
    std::cout << "WA" << std::endl;
    return 0;
  }

  long long length = s.length() - 3;
  std::string slicedS = s.substr(2, length);
  long long cCounter = 0;
  for (long long i = 0; i < slicedS.length(); i++) {
    if (slicedS.substr(i, 1) == "C") {
      cCounter++;
      s.erase(s.begin() + i + 2);
    }
  }

  if (cCounter != 1) {
    std::cout << "WA" << std::endl;
    return 0;
  }

  s.erase(s.begin());
  std::string sCopy = s;
  std::transform(s.begin(), s.end(), s.begin(), tolower);
  if (s != sCopy) {
    std::cout << "WA" << std::endl;
    return 0;
  }
  std::cout << "AC" << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

int main() {

  std::string s;
  std::cin >> s;

  if (s.substr(0, 1) != "A") {
    std::cout << "WA" << std::endl;
    return 0;
  }

  long long length = s.length() - 3;
  std::string slicedS = s.substr(2, length);
  long long cCounter = 0;
  for (long long i = 0; i < slicedS.length(); i++) {
    if (slicedS.substr(i, 1) == "C") {
      cCounter++;
      s.erase(s.begin() + i + 2);
      if (cCounter > 2) {
        std::cout << "WA" << std::endl;
        return 0;
      }
    }
  }

  if (cCounter != 1) {
    std::cout << "WA" << std::endl;
    return 0;
  }

  s.erase(s.begin());
  std::string sCopy = s;
  std::transform(s.begin(), s.end(), s.begin(), tolower);
  if (s != sCopy) {
    std::cout << "WA" << std::endl;
    return 0;
  }
  std::cout << "AC" << std::endl;
  return 0;
}
Problem p03289 (C++)

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

char A[15];

int main() {
  scanf("%s", A + 1);
  int n = strlen(A + 1);
  bool st = true;
  if (A[1] != 'A')
    st = false;
  vector<int> posC;
  for (int i = 1; i <= n; ++i) {
    if (A[i] == 'C')
      posC.emplace_back(i);
  }
  if (posC.size() != 1)
    st = false;
  if (!(posC[0] >= 3 && posC[0] < n))
    st = false;
  A[1] = 'a', A[posC[0]] = 'c';
  for (int i = 1; i <= n; ++i)
    if (A[i] <= 'Z')
      st = false;
  puts(st ? "AC" : "WA");
}

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

char A[15];

int main() {
  scanf("%s", A + 1);
  int n = strlen(A + 1);
  bool st = true;
  if (A[1] != 'A')
    st = false;
  vector<int> posC;
  for (int i = 1; i <= n; ++i) {
    if (A[i] == 'C')
      posC.emplace_back(i);
  }
  if (posC.size() != 1)
    st = false;
  if (!st)
    return !printf("WA");
  if (!(posC[0] >= 3 && posC[0] < n))
    st = false;
  A[1] = 'a', A[posC[0]] = 'c';
  for (int i = 1; i <= n; ++i)
    if (A[i] <= 'Z')
      st = false;
  puts(st ? "AC" : "WA");
}
Problem p03289 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <typename T> void pv(vector<T> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}

template <> void pv(vector<P> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << "<" << v.fi << "," << v.se << ">"
         << ",";
  }
  cout << "]" << endl;
}

int main() {
  string s;
  cin >> s;

  bool flag = true;
  if (s[0] != 'A')
    flag = false;
  string ss = s.substr(2, s.size() - 3);
  int cnt = 0;
  rep(i, ss.size()) if (ss.at(i) == 'C') cnt++;
  if (cnt != 1)
    flag = false;
  rep(i, s.size()) {
    char c = s.at(i);
    if (c == 'A')
      continue;
    if (c == 'C')
      continue;
    if (isupper(c))
      flag = false;
  }
  if (s.at(1) == 'C')
    flag = false;
  if (s.at(s.size()) == 'C')
    flag = false;
  if (flag)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <typename T> void pv(vector<T> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}

template <> void pv(vector<P> vec) {
  cout << "[";
  for (auto &v : vec) {
    cout << "<" << v.fi << "," << v.se << ">"
         << ",";
  }
  cout << "]" << endl;
}

int main() {
  string s;
  cin >> s;

  bool flag = true;
  if (s[0] != 'A')
    flag = false;
  string ss = s.substr(2, s.size() - 3);
  int cnt = 0;
  rep(i, ss.size()) if (ss.at(i) == 'C') cnt++;
  if (cnt != 1)
    flag = false;
  rep(i, s.size()) {
    char c = s.at(i);
    if (c == 'A')
      continue;
    if (c == 'C')
      continue;
    if (isupper(c))
      flag = false;
  }
  if (s.at(1) == 'C')
    flag = false;
  if (s.at(s.size() - 1) == 'C')
    flag = false;
  if (flag)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;

  return 0;
}
Problem p03289 (C++)

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

int main() {
  string S;
  cin >> S;
  bool flag = false;

  if (S.at(0) == 'A' && islower(S.at(1)) && islower(S.at(S.size() - 1)) &&
      S.at(S.at(S.size() - 1)) != 'C') {
    int count = 0;
    for (int i = 2; i < S.size() - 1; ++i) {
      if (S.at(i) == 'C') {
        count++;
      }
    }

    if (count > 1 || count == 0) {
      flag = true;
    }
  } else {
    flag = true;
  }

  if (flag == true) {
    cout << "WA" << endl;
  } else {
    cout << "AC" << endl;
  }
}

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

int main() {
  string S;
  cin >> S;
  bool flag = false;

  if (S.at(0) == 'A' && islower(S.at(1)) && islower(S.at(S.size() - 1)) &&
      S.at(S.size() - 1) != 'C') {
    int count = 0;
    for (int i = 2; i < S.size() - 1; ++i) {
      if (S.at(i) == 'C') {
        count++;
      }
    }

    if (count > 1 || count == 0) {
      flag = true;
    }
  } else {
    flag = true;
  }

  if (flag == true) {
    cout << "WA" << endl;
  } else {
    cout << "AC" << endl;
  }
}
Problem p03289 (Python)

Buggy submission (status: Runtime Error):
S = input()

if S[0] == "A" and S[2:-1].count("C") == 1 and sum([c.isupper for c in S]) == 2:
    print("AC")
else:
    print("WA")


Fixed submission:
S = input()

if S[0] == "A" and S[2:-1].count("C") == 1 and sum([c.isupper() for c in S]) == 2:
    print("AC")
else:
    print("WA")
Problem p03289 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i, a, b) for (lli i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define inf 7 + 1e18
#define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  string s;
  cin >> s;
  lli a = 0, b = 0, c = 0;

  if (s[0] == 'A')
    a = 1;
  loopl(i, 2, s.size() - 1) {
    if (s[i] == 'C')
      c++;
    if (s[i] - 'A' >= 0 && s[i] - 'A' <= 25)
      b++;
  }

  if (s[s.size() - 1] - 'A' >= 0 && s[s.size() - 1] - 'A' <= 25)
    b++;
  if (s[1] - 'A' >= 0 && s[1] - 'A' <= 25)
    b++;

  if ((a == 1 && c == 1) && b == 1)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i, a, b) for (lli i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define inf 7 + 1e18
#define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std;

int main() {

  string s;
  cin >> s;
  lli a = 0, b = 0, c = 0;

  if (s[0] == 'A')
    a = 1;
  loopl(i, 2, s.size() - 1) {
    if (s[i] == 'C')
      c++;
    if (s[i] - 'A' >= 0 && s[i] - 'A' <= 25)
      b++;
  }

  if (s[s.size() - 1] - 'A' >= 0 && s[s.size() - 1] - 'A' <= 25)
    b++;
  if (s[1] - 'A' >= 0 && s[1] - 'A' <= 25)
    b++;

  if ((a == 1 && c == 1) && b == 1)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
}
Problem p03290 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int D, G;
vi p, c;

int dfs(vi x, int res, int sum, int i) {

  REP(j, p[i]) {
    sum += (i + 1) * 100;
    res++;
    if (j + 1 == p[i])
      sum += c[i];
    if (sum >= G)
      return res;
  }

  int res2 = (1 << 30);
  REP(d, D) {
    if (x[d] > 0) {
      vi x2 = x;
      x2[d] = 0;
      res2 = min(res2, dfs(x2, res, sum, d));
    }
  }

  return res2;
}

int main() {

  cin >> D >> G;
  REP(i, D) {
    int a, b;
    cin >> a >> b;
    p.push_back(a);
    c.push_back(b);
  }

  vi x(D, 1);

  int ans = (1 << 30);
  REP(i, D) {
    vi x2 = x;
    x2[i] = 0;
    ans = min(ans, dfs(x2, 0, 0, i));
  }

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


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int D, G;
vi p, c;

int dfs(vi x, int res, int sum, int i) {

  if (sum + (i + 1) * p[i] * 100 + c[i] < G) {
    sum += (i + 1) * p[i] * 100 + c[i];
    res += p[i];
  } else {
    REP(j, p[i]) {
      sum += (i + 1) * 100;
      res++;
      if (j + 1 == p[i])
        sum += c[i];
      if (sum >= G)
        return res;
    }
  }

  int res2 = (1 << 30);
  REP(d, D) {
    if (x[d] > 0) {
      vi x2 = x;
      x2[d] = 0;
      res2 = min(res2, dfs(x2, res, sum, d));
    }
  }

  return res2;
}

int main() {

  cin >> D >> G;
  REP(i, D) {
    int a, b;
    cin >> a >> b;
    p.push_back(a);
    c.push_back(b);
  }

  vi x(D, 1);

  int ans = (1 << 30);
  REP(i, D) {
    vi x2 = x;
    x2[i] = 0;
    ans = min(ans, dfs(x2, 0, 0, i));
  }

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

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

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mst(a, v) memset(a, v, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

const int N = 100010;
const int mod = 1e9 + 7;
const ld PI = acos(-1.0);
const int inf = 0x3f3f3f3f;

int n, m, ans = inf;
pi a[20];

int main() {
#ifdef local
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> a[i].f >> a[i].s;
  int t = 1 << n;
  for (int i = 1; i < t; i++) {
    int sum = m, cnt = 0;
    for (int j = n - 1; ~j; j--) {
      if ((1 << j) & i) {
        int tt = a[j].f * (j + 1) * 100;
        if (tt >= sum) {
          cnt += (sum + 100 * j - 1) / (100 * j);
          sum = 0;
        } else {
          cnt += a[j].f;
          sum -= tt + a[j].s;
        }
        if (sum <= 0)
          break;
      }
    }
    if (sum <= 0)
      ans = min(ans, cnt);
  }
  cout << ans;
  return 0;
}


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

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mst(a, v) memset(a, v, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

const int N = 100010;
const int mod = 1e9 + 7;
const ld PI = acos(-1.0);
const int inf = 0x3f3f3f3f;

int n, m, ans = inf;
pi a[20];

int main() {
#ifdef local
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> a[i].f >> a[i].s;
  int t = 1 << n;
  for (int i = 1; i < t; i++) {
    int sum = m, cnt = 0;
    for (int j = n - 1; ~j; j--) {
      if ((1 << j) & i) {
        int tt = a[j].f * (j + 1) * 100;
        if (tt >= sum) {
          cnt += (sum + 100 * (j + 1) - 1) / (100 * (j + 1));
          sum = 0;
        } else {
          cnt += a[j].f;
          sum -= tt + a[j].s;
        }
        if (sum <= 0)
          break;
      }
    }
    if (sum <= 0)
      ans = min(ans, cnt);
  }
  cout << ans;
  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <vector>

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

// 完全に解いた場合の組み合わせのみ考える
// G点を目指す
int main() {

  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());

  //    ios::sync_with_stdio(false);
  //    cin.tie(0);
  ll d, g;
  cin >> d >> g;

  vector<ll> p(d);
  vector<ll> c(d);
  ll iMin = INF;
  REP(i, d) { cin >> p[i] >> c[i]; }

  for (int bit = 0; bit < (1 << d); ++bit) {
    ll cnt = 0;
    ll res = 0;

    for (int i = 0; i < d; ++i) {
      if (res >= g)
        break;
      if (bit & (1 << i)) {
        // 全部解けるなら
        res += (i + 1) * p[i] * 100;
        res += c[i];
        cnt += p[i];
      }
    }

    for (int i = d - 1; i >= 0; --i) {
      if (res >= g)
        break;
      if (!(bit & (1 << i))) {
        // zanの消化
        for (int j = 0; j < p[i]; ++j) {
          if (res >= g)
            break;
          res += (i + 1) * 100;
          ++cnt;
        }
        break;
      }
    }

    if (res >= g) {
      iMin = min(iMin, cnt);
    }
  }

  cout << iMin << endl;

  return 0;
}


Fixed submission:
#include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <vector>

#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

// 完全に解いた場合の組み合わせのみ考える
// G点を目指す
int main() {

  //    std::ifstream in("input.txt");
  //    std::cin.rdbuf(in.rdbuf());

  //    ios::sync_with_stdio(false);
  //    cin.tie(0);
  ll d, g;
  cin >> d >> g;

  vector<ll> p(d);
  vector<ll> c(d);
  ll iMin = INF;
  REP(i, d) { cin >> p[i] >> c[i]; }

  for (int bit = 0; bit < (1 << d); ++bit) {
    ll cnt = 0;
    ll res = 0;

    for (int i = 0; i < d; ++i) {
      if (res >= g)
        break;
      if (bit & (1 << i)) {
        // 全部解けるなら
        res += (i + 1) * p[i] * 100;
        res += c[i];
        cnt += p[i];
      }
    }

    for (int i = d - 1; i >= 0; --i) {
      if (res >= g)
        break;
      if (!(bit & (1 << i))) {
        // zanの消化
        for (int j = 0; j < p[i]; ++j) {
          if (res >= g)
            break;
          res += (i + 1) * 100;
          ++cnt;
        }
        break;
      }
    }

    if (res >= g) {
      iMin = min(iMin, cnt);
    }
  }

  cout << iMin << endl;

  return 0;
}
Problem p03290 (C++)

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

int main() {
  int D, G;
  cin >> D >> G;
  int p[10], c[10];
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  // cout << "debug";
  int ans = 100000;
  for (int i = 0; i < (1 << D); i++) {
    int tmpCnt = 0, tmpScore = 0;
    for (int j = 0; j < D; j++) {
      if ((1 << j) & i) {
        tmpCnt += p[j];
        tmpScore += p[j] * (j + 1) * 100 + c[j];
      }
    }
    for (int j = D - 1; tmpScore < G; j--) {
      if ((1 << j) & i) {
        continue;
      } else {
        int problemScore = (j + 1) * 100;
        int plusCnt =
            min(p[j], (G - tmpScore + problemScore - 1) / problemScore);
        tmpScore += plusCnt * problemScore;
        tmpCnt += plusCnt;
      }
    }
    ans = min(ans, tmpCnt);
  }
  cout << ans << endl;
}


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

int main() {
  int D, G;
  cin >> D >> G;
  int p[10], c[10];
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  // cout << "debug";
  int ans = 100000;
  for (int i = 0; i < (1 << D); i++) {
    int tmpCnt = 0, tmpScore = 0;
    for (int j = 0; j < D; j++) {
      if ((1 << j) & i) {
        tmpCnt += p[j];
        tmpScore += p[j] * (j + 1) * 100 + c[j];
      }
    }
    for (int j = D - 1; tmpScore < G && j >= 0; j--) {
      if ((1 << j) & i) {
        continue;
      } else {
        int problemScore = (j + 1) * 100;
        int plusCnt =
            min(p[j], (G - tmpScore + problemScore - 1) / problemScore);
        tmpScore += plusCnt * problemScore;
        tmpCnt += plusCnt;
      }
    }
    ans = min(ans, tmpCnt);
  }
  cout << ans << endl;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e8;
ll D, G;
int main() {
  cin >> D >> G;
  vector<ll> P(D), C(D);
  for (int i = 1; i <= D; ++i) {
    cin >> P[i] >> C[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;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e8;
ll D, G;
int main() {
  cin >> D >> G;
  vector<ll> P(D), C(D);
  for (int i = 0; i < D; ++i) {
    cin >> P[i] >> C[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;
  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D, G;
  cin >> D >> G;
  vector<P> v(11);
  REP(i, D) cin >> v[i].first >> v[i].second;

  int c_min = INF;

  REP(mask, 1 << D) {
    int p_sum = 0; // 問題数
    int c_sum = 0; // 特点
    int rest_max = -1;
    REP(i, D) {
      // bitが立っているならば，+する
      if (mask >> i & 1) {
        p_sum += v[i].first;
        c_sum += (i + 1) * 100 * v[i].first + v[i].second;
      } else {
        rest_max = i;
      }
      if (c_sum < G) {
        int s1 = 100 * (rest_max + 1);
        int need = (G - c_sum + s1 - 1) / s1;
        if (need >= v[rest_max].first)
          continue;
        p_sum += need;
      }
    }
    c_min = min(c_min, p_sum);
  }
  cout << c_min << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D, G;
  cin >> D >> G;
  vector<P> v(11);
  REP(i, D) cin >> v[i].first >> v[i].second;

  int c_min = INF;

  REP(mask, 1 << D) {
    int p_sum = 0; // 問題数
    int c_sum = 0; // 特点
    int rest_max = -1;
    REP(i, D) {
      // bitが立っているならば，+する
      if (mask >> i & 1) {
        p_sum += v[i].first;
        c_sum += (i + 1) * 100 * v[i].first + v[i].second;
      } else {
        rest_max = i;
      }
    }
    if (c_sum < G) {
      int s1 = 100 * (rest_max + 1);
      int need = (G - c_sum + s1 - 1) / s1;
      if (need >= v[rest_max].first)
        continue;
      p_sum += need;
    }
    c_min = min(c_min, p_sum);
  }
  cout << c_min << endl;
}
Problem p03290 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ios::sync_with_stdio(false);
  int d, g, ans = INT_MAX;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
  }
  for (int i = 0; i < (1 << d); i++) {
    int sum = 0, con = 0;
    vector<int> check(p);
    for (int j = 0; j < d; j++) {
      if (i & (1 << j)) {
        con += p[j];
        sum += (j + 1) * 100 * p[j] + c[j];
        check[j] = 0;
      }
    }
    if (sum < g) {
      vector<int> copy(p);
      for (int j = d - 1;; j--) {
        for (int k = 0; k < check[j]; k++) {
          sum += (j + 1) * 100;
          con++;
          if (sum >= g) {
            goto Exit;
          }
        }
      }
    }
  Exit:;
    if (sum >= g && con <= ans) {
      ans = con;
    }
  }
  cout << ans;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ios::sync_with_stdio(false);
  int d, g, ans = INT_MAX;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
  }
  for (int i = 0; i < (1 << d); i++) {
    int sum = 0, con = 0;
    vector<int> check(p);
    for (int j = 0; j < d; j++) {
      if (i & (1 << j)) {
        con += p[j];
        sum += (j + 1) * 100 * p[j] + c[j];
        check[j] = 0;
      }
    }
    if (sum < g) {
      vector<int> copy(p);
      for (int j = d - 1; j >= 0; j--) {
        for (int k = 0; k < check[j]; k++) {
          sum += (j + 1) * 100;
          con++;
          if (sum >= g) {
            goto Exit;
          }
        }
      }
    }
  Exit:;
    if (sum >= g && con <= ans) {
      ans = con;
    }
  }
  cout << ans;
}
Problem p03290 (C++)

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

int main() {
  int D, G, maxdgt, cnt, acm, rest, ans = 1000;
  cin >> D >> G;
  vector<int> P(D, 0);
  vector<int> C(D, 0);
  for (int i = 0; i < D; i++)
    cin >> P[i] >> C[i];

  for (int bit = 0; bit < (1 << D); bit++) {
    maxdgt = -1;
    cnt = 0;
    rest = G;
    for (int i = 0; i < D; i++) {
      if (bit & (1 << i)) {
        rest -= P[i] * (i + 1) * 100 + C[i];
        cnt += P[i];
      } else
        maxdgt = i;
    }
    if (rest < 0)
      ans = min(ans, cnt);
    else if ((P[maxdgt] - 1) * (maxdgt + 1) * 100 < rest)
      continue;
    else
      ans = min(ans, cnt + (rest / 100 - 1) / (maxdgt + 1) + 1);
  }
  cout << ans << "\n";
}

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

int main() {
  int D, G, maxdgt, cnt, acm, rest, ans = 1000;
  cin >> D >> G;
  vector<int> P(D, 0);
  vector<int> C(D, 0);
  for (int i = 0; i < D; i++)
    cin >> P[i] >> C[i];

  for (int bit = 0; bit < (1 << D); bit++) {
    maxdgt = -1;
    cnt = 0;
    rest = G;
    for (int i = 0; i < D; i++) {
      if (bit & (1 << i)) {
        rest -= P[i] * (i + 1) * 100 + C[i];
        cnt += P[i];
      } else
        maxdgt = i;
    }
    if (rest <= 0)
      ans = min(ans, cnt);
    else if ((P[maxdgt] - 1) * (maxdgt + 1) * 100 < rest)
      continue;
    else
      ans = min(ans, cnt + (rest / 100 - 1) / (maxdgt + 1) + 1);
  }
  cout << ans << "\n";
}
Problem p03290 (Python)

Buggy submission (status: Runtime Error):
from itertools import product
from math import ceil


def solve(string):
    d, g, *pc = map(int, string.split())
    g //= 100
    p = [_p for _p in pc[::2]]
    c = [_c // 100 for _c in pc[1::2]]
    ans = 1000
    for f in product([True, False], repeat=d):
        sums = sum(
            [(i + 1) * _p + _c for i, (_f, _p, _c) in enumerate(zip(f, p, c)) if _f]
        )
        counts = sum([_p for _f, _p in zip(f, p) if _f])
        if g <= sums:
            ans = min(ans, counts)
            continue

        indices = [i + 1 for i, _f in enumerate(f) if not _f]
        tmp = ceil((g - sums) / indices[-1])
        if tmp < p[indices[-1]]:
            ans = min(ans, counts + tmp)
    return str(ans)


if __name__ == "__main__":
    n, g = map(int, input().split())
    print(solve("{} {}\n".format(n, g) + "\n".join([input() for _ in range(n)])))


Fixed submission:
from itertools import product
from math import ceil


def solve(string):
    d, g, *pc = map(int, string.split())
    g //= 100
    p = [_p for _p in pc[::2]]
    c = [_c // 100 for _c in pc[1::2]]
    ans = 1000
    for f in product([True, False], repeat=d):
        sums = sum(
            [(i + 1) * _p + _c for i, (_f, _p, _c) in enumerate(zip(f, p, c)) if _f]
        )
        counts = sum([_p for _f, _p in zip(f, p) if _f])
        if g <= sums:
            ans = min(ans, counts)
            continue

        indices = [i + 1 for i, _f in enumerate(f) if not _f]
        tmp = ceil((g - sums) / indices[-1])
        if tmp < p[indices[-1] - 1]:
            ans = min(ans, counts + tmp)
    return str(ans)


if __name__ == "__main__":
    n, g = map(int, input().split())
    print(solve("{} {}\n".format(n, g) + "\n".join([input() for _ in range(n)])))
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int D = 10;
int Min = 1000000;
vector<int> p(D + 1, 0);
vector<int> c(D + 1, 0);
vector<int> B(D + 1, 0);

void dfs(int i, int count, long int score, vector<int> B) {
  if (i == D + 1) {
    int j;
    for (j = D; j >= 1; j--) {
      if (B[j] != 1)
        break;
    }
    if ((p[j] - 1) * 100 * j >= score) {
      if (score < 0)
        ;
      else if (score % (100 * j) != 0)
        count += score / (100 * j) + 1;
      else
        count += score / (100 * j);
      if (count < Min)
        Min = count;
    }
  } else {
    B[i] = 1;
    dfs(i + 1, count + p[i], score - p[i] * 100 * i - c[i], B);
    B[i] = 0;
    dfs(i + 1, count, score, B);
  }
  return;
}

int main() {
  long int G;
  int count = 0;
  cin >> D;
  cin >> G;
  for (int i = 1; i <= D; i++) {
    cin >> p[i] >> c[i];
  }
  dfs(1, count, G, B);
  cout << Min << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int D = 10;
int Min = 1000000;
vector<int> p(D + 1, 0);
vector<int> c(D + 1, 0);
vector<int> B(D + 1, 0);

void dfs(int i, int count, long int score, vector<int> B) {
  if (i == D + 1) {
    int j;
    for (j = D; j >= 1; j--) {
      if (B[j] != 1)
        break;
    }
    if ((p[j] - 1) * 100 * j >= score) {
      if (score <= 0)
        ;
      else if (score % (100 * j) != 0)
        count += score / (100 * j) + 1;
      else
        count += score / (100 * j);
      if (count < Min)
        Min = count;
    }
  } else {
    B[i] = 1;
    dfs(i + 1, count + p[i], score - p[i] * 100 * i - c[i], B);
    B[i] = 0;
    dfs(i + 1, count, score, B);
  }
  return;
}

int main() {
  long int G;
  int count = 0;
  cin >> D;
  cin >> G;
  for (int i = 1; i <= D; i++) {
    cin >> p[i] >> c[i];
  }
  dfs(1, count, G, B);
  cout << Min << endl;
  return 0;
}
Problem p03290 (C++)

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

int n, m, res = 1e9;
int table[100010];

int main() {
  int i, j, k, a, s;
  scanf("%d %d", &n, &m);
  m /= 100;
  table[0] = 1;
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &a, &s);
    s /= 100;
    for (j = m - 1; j >= 0; j--) {
      if (table[j]) {
        for (k = 1; k < a; k++) {
          if (!table[j + k * i])
            table[j + k * i] = table[j] + k;
          else
            table[j + k * i] = min(table[j + k * i], table[j] + k);
          if (j + k * i >= m)
            res = min(res, table[j + k * i] - 1);
        }
        if (!table[j + k * i + s])
          table[j + k * i + s] = table[j] + k;
        else
          table[j + k * i + s] = min(table[j + k * i + s], table[j] + k);
        if (j + k * i + s >= m)
          res = min(res, table[j + k * i + s] - 1);
      }
    }
  }
  printf("%d", res);
  return 0;
}


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

int n, m, res = 1e9;
int table[10000010];

int main() {
  int i, j, k, a, s;
  scanf("%d %d", &n, &m);
  m /= 100;
  table[0] = 1;
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &a, &s);
    s /= 100;
    for (j = m - 1; j >= 0; j--) {
      if (table[j]) {
        for (k = 1; k < a; k++) {
          if (!table[j + k * i])
            table[j + k * i] = table[j] + k;
          else
            table[j + k * i] = min(table[j + k * i], table[j] + k);
          if (j + k * i >= m)
            res = min(res, table[j + k * i] - 1);
        }
        if (!table[j + k * i + s])
          table[j + k * i + s] = table[j] + k;
        else
          table[j + k * i + s] = min(table[j + k * i + s], table[j] + k);
        if (j + k * i + s >= m)
          res = min(res, table[j + k * i + s] - 1);
      }
    }
  }
  printf("%d", res);
  return 0;
}
Problem p03290 (C++)

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

int dp[11010][2];

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

  int D, G;
  cin >> D >> G;
  G /= 100;

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

  for (int i = 0; i < G; ++i) {
    dp[i][0] = dp[i][1] = I_INF;
  }
  dp[0][0] = 0;

  int ans = I_INF;

  for (int di = 1; di <= D; ++di) {
    for (int pi = 1; pi <= p[di - 1]; ++pi) {
      for (int i = 0; i < G; ++i) {
        if (dp[i][0] == I_INF)
          continue;

        if (pi == p[di - 1]) {
          if (i + di * pi + c[di - 1] >= G) {
            ans = min(ans, dp[i][0] + pi);
          } else {
            dp[i + di * pi + c[di - 1]][1] =
                min(dp[i + di * pi + c[di - 1]][1], dp[i][0] + pi);
          }
        } else {
          if (i + di * pi >= G) {
            ans = min(ans, dp[i][0] + pi);
          } else {
            dp[i + di * pi][1] = min(dp[i + di * pi][1], dp[i][0] + pi);
          }
        }
      }
    }
    for (int i = 0; i < G; ++i) {
      dp[i][0] = min(dp[i][0], dp[i][1]);
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

int dp[10550010][2];

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

  int D, G;
  cin >> D >> G;
  G /= 100;

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

  for (int i = 0; i < G; ++i) {
    dp[i][0] = dp[i][1] = I_INF;
  }
  dp[0][0] = 0;

  int ans = I_INF;

  for (int di = 1; di <= D; ++di) {
    for (int pi = 1; pi <= p[di - 1]; ++pi) {
      for (int i = 0; i < G; ++i) {
        if (dp[i][0] == I_INF)
          continue;

        if (pi == p[di - 1]) {
          if (i + di * pi + c[di - 1] >= G) {
            ans = min(ans, dp[i][0] + pi);
          } else {
            dp[i + di * pi + c[di - 1]][1] =
                min(dp[i + di * pi + c[di - 1]][1], dp[i][0] + pi);
          }
        } else {
          if (i + di * pi >= G) {
            ans = min(ans, dp[i][0] + pi);
          } else {
            dp[i + di * pi][1] = min(dp[i + di * pi][1], dp[i][0] + pi);
          }
        }
      }
    }
    for (int i = 0; i < G; ++i) {
      dp[i][0] = min(dp[i][0], dp[i][1]);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03290 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, a) for (int i = 0; i < (a); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int main() {
  int i, j, k, D, G;
  cin >> D >> G;
  pair<int, int> tmp;
  vector<pair<int, int>> P;
  rep0(i, D) {
    cin >> tmp.first >> tmp.second;
    P.push_back(tmp);
  }
  int total, num, min_num;
  min_num = 1 << 30;
  rep0(i, (1 << D)) {
    total = 0;
    num = 0;
    bitset<10> bit(i);
    rep0(k, D) {
      if (bit.test(k)) {
        total += P[k].second + (100 * (k + 1) * P[k].first);
        num += P[k].first;
      }
    }
    // cout << bit << " " << total << ", " << num << endl;
    if (total >= G) {
      if (min_num > num) {
        min_num = num;
        continue;
      }
    }
    if (total < G) {
      for (k = D; k >= 0; k--) {
        if (!bit.test(k)) {

          if (P[k].first > (G - total) / (100 * (k + 1))) {

            if ((G - total) % (100 * (k + 1)) == 0) {
              num += (G - total) / (100 * (k + 1));
            } else {
              num += (G - total) / (100 * (k + 1)) + 1;
            }
            if (min_num > num) {
              min_num = num;
            }
            break;
          }
        }
      }
    }
  }

  cout << min_num << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, a) for (int i = 0; i < (a); i++)
#define rep(i, a, b) for (int i = (a); i < (b); i++)

int main() {
  int i, j, k, D, G;
  cin >> D >> G;
  pair<int, int> tmp;
  vector<pair<int, int>> P;
  rep0(i, D) {
    cin >> tmp.first >> tmp.second;
    P.push_back(tmp);
  }
  int total, num, min_num;
  min_num = 1 << 30;
  rep0(i, (1 << D)) {
    total = 0;
    num = 0;
    bitset<10> bit(i);
    rep0(k, D) {
      if (bit.test(k)) {
        total += P[k].second + (100 * (k + 1) * P[k].first);
        num += P[k].first;
      }
    }
    // cout << bit << " " << total << ", " << num << endl;
    if (total >= G) {
      if (min_num > num) {
        min_num = num;
        continue;
      }
    }
    if (total < G) {
      for (k = D - 1; k >= 0; k--) {
        if (!bit.test(k)) {

          if (P[k].first > (G - total) / (100 * (k + 1))) {

            if ((G - total) % (100 * (k + 1)) == 0) {
              num += (G - total) / (100 * (k + 1));
            } else {
              num += (G - total) / (100 * (k + 1)) + 1;
            }
            if (min_num > num) {
              min_num = num;
            }
            break;
          }
        }
      }
    }
  }

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

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

int main(void) {
  int D, G;
  cin >> D >> G;
  vector<int> p = vector<int>(D);
  vector<int> c = vector<int>(D);
  int result = 0;
  for (int i = 1; i <= D; i++) {
    cin >> p[i] >> c[i];
    result += p[i];
    c[i] /= 100;
  }

  // unordered_map<int, int> memo;
  map<int, int> memo;
  G /= 100;
  memo[0] = 0;
  for (int i = 1; i <= D; i++) {
    map<int, int> temp_memo;
    temp_memo = memo;
    for (auto it = temp_memo.begin(); it != temp_memo.end(); it++) {
      int source = it->first;
      int source_val = it->second;
      for (int j = 1; j <= p[i]; j++) {
        // int prev = source + i * (j - 1);
        if (memo.find(source + i * j) == memo.end()) {
          memo[source + i * j] = source_val + j;
        } else if (memo[source + i * j] > source_val + j) {
          memo[source + i * j] = source_val + j;
        }
      }

      int prev = source + i * p[i];
      if (memo.find(prev + c[i]) == memo.end()) {
        memo[prev + c[i]] = source_val + p[i];
      } else if (memo[prev + c[i]] > memo[source] + p[i]) {
        memo[prev + c[i]] = source_val + p[i];
      }
    }
  }

  for (auto it = memo.begin(); it != memo.end(); it++) {
    if (it->first >= G && result > it->second)
      result = it->second;
    // cout << it->first << ": " << it->second << endl;
  }
  cout << result << endl;
  return 0;
}


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

int main(void) {
  int D, G;
  cin >> D >> G;
  vector<int> p = vector<int>(D + 1);
  vector<int> c = vector<int>(D + 1);
  int result = 0;
  for (int i = 1; i <= D; i++) {
    cin >> p[i] >> c[i];
    result += p[i];
    c[i] /= 100;
  }

  // unordered_map<int, int> memo;
  map<int, int> memo;
  G /= 100;
  memo[0] = 0;
  for (int i = 1; i <= D; i++) {
    map<int, int> temp_memo;
    temp_memo = memo;
    for (auto it = temp_memo.begin(); it != temp_memo.end(); it++) {
      int source = it->first;
      int source_val = it->second;
      for (int j = 1; j <= p[i]; j++) {
        // int prev = source + i * (j - 1);
        if (memo.find(source + i * j) == memo.end()) {
          memo[source + i * j] = source_val + j;
        } else if (memo[source + i * j] > source_val + j) {
          memo[source + i * j] = source_val + j;
        }
      }

      int prev = source + i * p[i];
      if (memo.find(prev + c[i]) == memo.end()) {
        memo[prev + c[i]] = source_val + p[i];
      } else if (memo[prev + c[i]] > memo[source] + p[i]) {
        memo[prev + c[i]] = source_val + p[i];
      }
    }
  }

  for (auto it = memo.begin(); it != memo.end(); it++) {
    if (it->first >= G && result > it->second)
      result = it->second;
    // cout << it->first << ": " << it->second << endl;
  }
  cout << result << endl;
  return 0;
}
Problem p03290 (C++)

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

#define ll long long
#define mod 1000000007

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll d, g, ans = INT_MAX; // cout<<ceil((700-0)/(200+0.0))<<endl;
  cin >> d >> g;
  ll p[11], c[11];
  for (int i = 0; i < d; i++)
    cin >> p[i] >> c[i];
  for (int i = 0; i < (1 << d); i++) {
    ll s = 0, num = 0, restmax = -1;
    for (int j = 0; j < d; j++) {
      if (i >> j & 1) {
        s += 100 * (j + 1) * p[j] + c[j];
        num += p[j];
      } else
        restmax = i;
    }
    if (s < g) {
      ll s1 = 100 * (restmax + 1);
      if (s1 == 0)
        continue;
      ll need = ceil((g - s) / (s1 + 0.0));
      if (need >= p[restmax])
        continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}


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

#define ll long long
#define mod 1000000007

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll d, g, ans = INT_MAX; // cout<<ceil((700-0)/(200+0.0))<<endl;
  cin >> d >> g;
  ll p[11], c[11];
  for (int i = 0; i < d; i++)
    cin >> p[i] >> c[i];
  for (int i = 0; i < (1 << d); i++) {
    ll s = 0, num = 0, restmax = -1;
    for (int j = 0; j < d; j++) {
      if (i >> j & 1) {
        s += 100 * (j + 1) * p[j] + c[j];
        num += p[j];
      } else
        restmax = j;
    }
    if (s < g) {
      ll s1 = 100 * (restmax + 1);
      if (s1 == 0)
        continue;
      ll need = ceil((g - s) / (s1 + 0.0));
      if (need >= p[restmax])
        continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}