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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
#define mst(a, b) memset(a, b, sizeof a)
#define lx x << 1
#define rx x << 1 | 1
#define reg register
#define PII pair<int, int>
#define fi first
#define se second
#define pb push_back
#define il inline
struct p {
  ll l, r;
} a[N];
ll s;
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    a[i].l = x, a[i].r = a[i].l + t;
  }
  ll l = a[1].l, r = a[1].r;
  for (int i = 2; i <= n; i++) {
    if (a[i].l <= r)
      r = a[i].r;
    else
      s += r - l, l = a[i].l, r = a[i].r;
  }
  s += r - l;
  printf("%lld\n", s);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
#define mst(a, b) memset(a, b, sizeof a)
#define lx x << 1
#define rx x << 1 | 1
#define reg register
#define PII pair<int, int>
#define fi first
#define se second
#define pb push_back
#define il inline
struct p {
  ll l, r;
} a[N];
ll s;
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    a[i].l = x, a[i].r = a[i].l + t;
  }
  ll l = a[1].l, r = a[1].r;
  for (int i = 2; i <= n; i++) {
    if (a[i].l <= r)
      r = a[i].r;
    else
      s += r - l, l = a[i].l, r = a[i].r;
  }
  s += r - l;
  printf("%lld\n", s);
  return 0;
}
Problem p03731 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

int main() {
  long n, T, t[200];
  cin >> n >> T;
  for (int i = 0; i < n; i++)
    cin >> t[i];

  long sum = 0;
  for (int i = 0; i < n - 1; i++) {
    if (t[i] + T <= t[i + 1])
      sum += T;
    else {
      sum += t[i + 1] - t[i];
    }
  }
  sum += T;
  cout << sum << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

int main() {
  long n, T, t[300000];
  cin >> n >> T;
  for (int i = 0; i < n; i++)
    cin >> t[i];

  long sum = 0;
  for (int i = 0; i < n - 1; i++) {
    if (t[i] + T <= t[i + 1])
      sum += T;
    else {
      sum += t[i + 1] - t[i];
    }
  }
  sum += T;
  cout << sum << endl;
}
Problem p03731 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#define ll long long
#define inf 1000000000LL
#define mod 1000000007
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
pair<ll, ll> B[N * 2];
int main() {
  while (true) {
    int n = read(), t = read();
    int top = 0;
    ll x;
    for (int i = 0; i < n; i++) {
      x = read();
      B[top].first = x;
      B[top].second = -1;
      top++;
      // cout<<x+t<<endl;
      B[top].first = x + t;
      B[top].second = 1;
      top++;
    }
    sort(B, B + top);
    int count = 0;
    ll pre = 0, ans = 0;
    bool first = 1;
    for (int i = 0; i < top; i++) {
      if (B[i].second == 1) {
        count++;
        if (count == 0) {
          //  cout<<B[i].first<<" "<<pre<<endl;
          ans += B[i].first - pre;
        }
      }
      if (B[i].second == -1) {
        count--;
        if (count == -1) {
          pre = B[i].first;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#define ll long long
#define inf 1000000000LL
#define mod 1000000007
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
pair<ll, ll> B[N * 2];
int main() {
  // while(true)
  {
    int n = read(), t = read();
    int top = 0;
    ll x;
    for (int i = 0; i < n; i++) {
      x = read();
      B[top].first = x;
      B[top].second = -1;
      top++;
      // cout<<x+t<<endl;
      B[top].first = x + t;
      B[top].second = 1;
      top++;
    }
    sort(B, B + top);
    int count = 0;
    ll pre = 0, ans = 0;
    bool first = 1;
    for (int i = 0; i < top; i++) {
      if (B[i].second == 1) {
        count++;
        if (count == 0) {
          //  cout<<B[i].first<<" "<<pre<<endl;
          ans += B[i].first - pre;
        }
      }
      if (B[i].second == -1) {
        count--;
        if (count == -1) {
          pre = B[i].first;
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
Problem p03731 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, t;
  int time[1000];
  int i, j, sum = 0, tt = 0;
  cin >> n >> t;
  int a, b, c;
  for (i = 0; i < n; i++) {
    cin >> time[i];
  }
  tt = t;
  for (i = 1; i < n; i++) {
    if (time[i] - time[i - 1] < t) {
      sum += time[i] - time[i - 1];
    } else {
      sum += t;
    }
  }
  sum += t;
  cout << sum << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, t;
  int time[1000000];
  int i, j, sum = 0, tt = 0;
  cin >> n >> t;
  int a, b, c;
  for (i = 0; i < n; i++) {
    cin >> time[i];
  }
  tt = t;
  for (i = 1; i < n; i++) {
    if (time[i] - time[i - 1] < t) {
      sum += time[i] - time[i - 1];
    } else {
      sum += t;
    }
  }
  sum += t;
  cout << sum << endl;
}
Problem p03731 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string.h> //for strlen
using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  int temp[100000];
  int total = 0;
  for (int i = 0; i < N; i++) {

    cin >> temp[i];
    if (i == 0)
      continue;
    if (temp[i] - temp[i - 1] - T > 0)
      total = total + T;
    else
      total = total + temp[i] - temp[i - 1];
  }

  cout << total + T << endl;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string.h> //for strlen
using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  int temp[10000000];
  int total = 0;
  for (int i = 0; i < N; i++) {

    cin >> temp[i];
    if (i == 0)
      continue;
    if (temp[i] - temp[i - 1] - T > 0)
      total = total + T;
    else
      total = total + temp[i] - temp[i - 1];
  }

  cout << total + T << endl;
}
Problem p03731 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  long long int n, T;
  cin >> n >> T;
  long long int ans = 0;
  long long int t[100001];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min(t[i + 1] - t[i], T);
  }
  ans += T;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  long long int n, T;
  cin >> n >> T;
  long long int ans = 0;
  long long int t[200001];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans += min(t[i + 1] - t[i], T);
  }
  ans += T;
  cout << ans << endl;
  return 0;
}
Problem p03731 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;

#define C cout <<
#define E << endl

ll n, m, a, b, c, x, y, z, aa[100010], ab[100010], ac[100010];
bool r, ra, rb, rc;
string s, sa, sb, sc;
char ca, cb, cc, cd[1000][1000];
vector<ll> va, vb, vc;

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> aa[i];
  c = 0;
  for (int i = 1; i < n; i++) {
    c += min(m, aa[i] - aa[i - 1]);
  }
  C c + m E;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int ll;

#define C cout <<
#define E << endl

ll n, m, a, b, c, x, y, z, aa[200010], ab[100010], ac[100010];
bool r, ra, rb, rc;
string s, sa, sb, sc;
char ca, cb, cc, cd[1000][1000];
vector<ll> va, vb, vc;

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> aa[i];
  c = 0;
  for (int i = 1; i < n; i++) {
    c += min(m, aa[i] - aa[i - 1]);
  }
  C c + m E;
}
Problem p03731 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

ll t[100010];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  // cout << fixed << setprecision(7);

  ll N, T;
  cin >> N >> T;
  for (int i = 0; i < N; ++i) {
    cin >> t[i];
  }

  ll ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (t[i + 1] - t[i] >= T) {
      ans += T;
    } else {
      int idx = 0;
      while (i + idx < N) {
        if (t[i + idx] - t[i] >= T)
          break;
        idx++;
      }
      idx--;
      ans += t[i + idx] - t[i];
      i = i + idx - 1;
    }
  }
  ans += T;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

ll t[200010];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  // cout << fixed << setprecision(7);

  ll N, T;
  cin >> N >> T;
  for (int i = 0; i < N; ++i) {
    cin >> t[i];
  }

  ll ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (t[i + 1] - t[i] >= T) {
      ans += T;
    } else {
      int idx = 0;
      while (i + idx < N) {
        if (t[i + idx] - t[i] >= T)
          break;
        idx++;
      }
      idx--;
      ans += t[i + idx] - t[i];
      i = i + idx - 1;
    }
  }
  ans += T;
  cout << ans << endl;
  return 0;
}
Problem p03731 (C++)

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

int main(void) {
  int N, T, z, X, t[20], A[20];

  X = 0;

  cin >> N >> T;

  for (int s = 1; s <= N; s++) {
    cin >> t[s];
  }

  for (int i = 1; i <= N - 1; i++) {
    if ((t[i + 1] - t[i]) > T)
      A[i] = T;
    else
      A[i] = t[i + 1] - t[i];
  }

  for (int k = 1; k <= N - 1; k++) {
    z = A[k];
    X = X + z;
  }
  X = X + T;

  cout << X << endl;
}

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

int main(void) {
  long long N, T, z, X, t[200000], A[20000];

  X = 0;

  cin >> N >> T;

  for (int s = 1; s <= N; s++) {
    cin >> t[s];
  }

  for (int i = 1; i <= N - 1; i++) {
    if ((t[i + 1] - t[i]) > T)
      A[i] = T;
    else
      A[i] = t[i + 1] - t[i];
  }

  for (int k = 1; k <= N - 1; k++) {
    z = A[k];
    X = X + z;
  }
  X = X + T;

  cout << X << endl;
}
Problem p03731 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, T;
  long long t[N];
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }
  long long ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (t[i + 1] - t[i] < T) {
      ans += t[i + 1] - t[i];
    } else {
      ans += T;
    }
  }
  cout << ans + T << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, T;
  long long t[N];
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }
  long long ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (t[i + 1] - t[i] < T) {
      ans += t[i + 1] - t[i];
    } else {
      ans += T;
    }
  }
  cout << ans + T << endl;
  return 0;
}
Problem p03731 (C++)

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

int n, t;
int f[100010];
long long ans;

int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; i++)
    scanf("%d", &f[i]);
  for (int i = 1; i < n; i++)
    ans += min(f[i + 1] - f[i], t);
  cout << ans + t << endl;
}

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

int n, t;
int f[200010];
long long ans;

int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; i++)
    scanf("%d", &f[i]);
  for (int i = 1; i < n; i++)
    ans += min(f[i + 1] - f[i], t);
  cout << ans + t << endl;
}
Problem p03732 (C++)

Buggy submission (status: Runtime Error):
/*
        Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define fi(a, b, c, d) for (int a = b; i < c; i += d)
#define fl(a, b, c, d) for (ll a = b; i < c; i += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
map<ll, ll> cache[5];
vector<ll> V;
set<ll> S;

int main() {
  scanf("%lld %lld", &N, &M);
  for (int i = 1; i <= N; i++) {
    scanf("%lld %lld", &arr[i], &arr1[i]);
  }
  ll X = 0;
  cache[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    ll Y = X;
    X ^= 1;
    cache[X].clear();
    for (auto x : cache[Y]) {
      cache[X][x.ff] = max(cache[X][x.ff], x.ss);
      if (x.ff + arr[i] <= M) {
        cache[X][x.ff + arr[i]] = max(cache[X][x.ff + arr[i]], x.ss + arr1[i]);
      }
    }
  }
  ll ans = 0;
  for (auto x : cache[X]) {
    ans = max(ans, x.ss);
  }
  printf("%lld\n", ans);

  return 0;
}
/*
        Powered by Buggy Plugin
*/


Fixed submission:
/*
        Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 105
#define fi(a, b, c, d) for (int a = b; i < c; i += d)
#define fl(a, b, c, d) for (ll a = b; i < c; i += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
map<ll, ll> cache[5];
vector<ll> V;
set<ll> S;

int main() {
  scanf("%lld %lld", &N, &M);
  for (int i = 1; i <= N; i++) {
    scanf("%lld %lld", &arr[i], &arr1[i]);
  }
  ll X = 0;
  cache[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    ll Y = X;
    X ^= 1;
    cache[X].clear();
    for (auto x : cache[Y]) {
      cache[X][x.ff] = max(cache[X][x.ff], x.ss);
      if (x.ff + arr[i] <= M) {
        cache[X][x.ff + arr[i]] = max(cache[X][x.ff + arr[i]], x.ss + arr1[i]);
      }
    }
  }
  ll ans = 0;
  for (auto x : cache[X]) {
    ans = max(ans, x.ss);
  }
  printf("%lld\n", ans);

  return 0;
}
/*
        Powered by Buggy Plugin
*/
Problem p03732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, m, n) for (int i = m; i < n; i++)
ll mod = 1e9 + 7;

int main() {
  int n;
  ll W;
  cin >> n >> W;
  ll w[n];
  int v[n];
  vector<int> a[4];
  rep(i, 0, n) { cin >> w[i] >> v[i]; }
  rep(i, 0, n) { a[w[i] - w[0]].push_back(v[i]); }
  rep(i, 0, 4) { sort(a[i].rbegin(), a[i].rend()); }
  vector<int> b[4];
  rep(i, 0, 4) {
    b[i].push_back(0);
    rep(j, 0, a[i].size()) { b[i].push_back(b[i][b[i].size() - 1] + a[i][j]); }
  }
  int ans = 0;
  rep(i, 0, b[0].size()) {
    rep(j, 0, b[1].size()) {
      rep(k, 0, b[2].size()) {
        rep(l, 0, b[3].size()) {
          if (i * w[0] + j * (w[0] + 1) + k * (w[0] + 2) + l * (w[0] + 3) <=
              W) {
            ans = max(ans, b[0][i] + b[i][j] + b[2][k] + b[3][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, m, n) for (int i = m; i < n; i++)
ll mod = 1e9 + 7;

int main() {
  int n;
  ll W;
  cin >> n >> W;
  ll w[n];
  int v[n];
  vector<int> a[4];
  rep(i, 0, n) { cin >> w[i] >> v[i]; }
  rep(i, 0, n) { a[w[i] - w[0]].push_back(v[i]); }
  rep(i, 0, 4) { sort(a[i].rbegin(), a[i].rend()); }
  vector<int> b[4];
  rep(i, 0, 4) {
    b[i].push_back(0);
    rep(j, 0, a[i].size()) { b[i].push_back(b[i][b[i].size() - 1] + a[i][j]); }
  }
  int ans = 0;
  rep(i, 0, b[0].size()) {
    rep(j, 0, b[1].size()) {
      rep(k, 0, b[2].size()) {
        rep(l, 0, b[3].size()) {
          if (i * w[0] + j * (w[0] + 1) + k * (w[0] + 2) + l * (w[0] + 3) <=
              W) {
            ans = max(ans, b[0][i] + b[1][j] + b[2][k] + b[3][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
// ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

vector<vector<vector<ll>>> dp(110, vector<vector<ll>>(110, vector<ll>(410)));

int main() {
  ll N, W;
  cin >> N >> W;
  rep(i, 110) rep(j, 110) rep(k, 410) dp[i][j][k] = 0;
  vector<ll> v(N), w(N);
  rep(i, N) { cin >> w[i] >> v[i]; }
  ll base = w[0];
  rep(i, N) { w[i] -= base; }
  rep(i, N) {
    rep(j, N) {
      rep(k, 410) {
        if (w[i] <= k) {
          dp[i + 1][j + 1][k] = max(dp[i][j][k - w[i]] + v[i], dp[i][j + 1][k]);
        } else {
          dp[i + 1][j + 1][k] = dp[i][j + 1][k];
        }
      }
    }
  }
  ll ans = 0;
  rep(i, N + 1) {
    if (W - i * base < 0)
      break;
    ans = max(ans, dp[N][i][W - base * i]);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
// ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

vector<vector<vector<ll>>> dp(110, vector<vector<ll>>(110, vector<ll>(410)));

int main() {
  ll N, W;
  cin >> N >> W;
  rep(i, 110) rep(j, 110) rep(k, 410) dp[i][j][k] = 0;
  vector<ll> v(N), w(N);
  rep(i, N) { cin >> w[i] >> v[i]; }
  ll base = w[0];
  rep(i, N) { w[i] -= base; }
  rep(i, N) {
    rep(j, N) {
      rep(k, 410) {
        if (w[i] <= k) {
          dp[i + 1][j + 1][k] = max(dp[i][j][k - w[i]] + v[i], dp[i][j + 1][k]);
        } else {
          dp[i + 1][j + 1][k] = dp[i][j + 1][k];
        }
      }
    }
  }
  ll ans = 0;
  rep(i, N + 1) {
    if (W - i * base < 0)
      break;
    ans = max(ans, dp[N][i][min(W - base * i, 3 * N)]);
  }
  cout << ans << endl;
}
Problem p03732 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long MOD = 1e9 + 7;

int N;
vector<long long> V, W;
long long Wmax;
vector<vector<vector<long long>>> DP;

int main() {
  cin >> N >> Wmax;
  V.resize(N + 1);
  W.resize(N + 1);
  for (int n = 1; n <= N; n++) {
    cin >> W[n] >> V[n];
  }
  DP.resize(N + 1,
            vector<vector<long long>>(N + 1, vector<long long>(301, -1)));
  DP[0][0][0] = 0;
  for (int n = 1; n <= N; n++) {
    DP[n][0][0] = 0;
    for (int k = 1; k <= n; k++)
      for (int w = 0; w <= 300; w++) {
        DP[n][k][w] = DP[n - 1][k][w];
        if (w - W[n] + W[1] >= 0) {
          DP[n][k][w] =
              max(DP[n][k][w], DP[n - 1][k - 1][w - W[n] + W[1]] + V[n]);
        }
      }
  }
  long long ans = 0;
  for (int k = 0; k <= N; k++) {
    for (int w = 0; w <= Wmax - k * W[1]; w++) {
      ans = max(ans, DP[N][k][w]);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long MOD = 1e9 + 7;

int N;
vector<long long> V, W;
long long Wmax;
vector<vector<vector<long long>>> DP;

int main() {
  cin >> N >> Wmax;
  V.resize(N + 1);
  W.resize(N + 1);
  for (int n = 1; n <= N; n++) {
    cin >> W[n] >> V[n];
  }
  DP.resize(N + 1,
            vector<vector<long long>>(N + 1, vector<long long>(301, -1)));
  DP[0][0][0] = 0;
  for (int n = 1; n <= N; n++) {
    DP[n][0][0] = 0;
    for (int k = 1; k <= n; k++)
      for (int w = 0; w <= 300; w++) {
        DP[n][k][w] = DP[n - 1][k][w];
        if (w - W[n] + W[1] >= 0) {
          DP[n][k][w] =
              max(DP[n][k][w], DP[n - 1][k - 1][w - W[n] + W[1]] + V[n]);
        }
      }
  }
  long long ans = 0;
  for (int k = 0; k <= N; k++) {
    for (int w = 0; w <= min((long long)300, Wmax - k * W[1]); w++) {
      ans = max(ans, DP[N][k][w]);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03732 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#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 = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;

int main() {
  ll n, W;
  cin >> n >> W;
  vector<ll> w(n);
  vector<ll> ww(n);
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
    ww[i] = w[i] - w[0];
  }
  vector<vector<vector<ll>>> dp(
      n + 1, vector<vector<ll>>(n + 1, vector<ll>(600, 0LL)));
  // dp[i][j][k] i番目までを使ってj個使用して重さがkのときの価値の最大値
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      for (ll k = 0; k < 500; k++) {
        if (ww[i - 1] <= k) {
          dp[i][j][k] =
              max(dp[i - 1][j][k], dp[i - 1][j - 1][k - ww[i - 1]] + v[i - 1]);
        } else {
          dp[i][j][k] = dp[i - 1][j][k];
        }
      }
    }
  }

  ll ans = 0LL;
  for (ll i = 0; i <= n; i++) {
    ll k = 0;
    while (W - i * w[0] >= k) {
      ans = max(ans, dp[n][i][k]);
      k++;
    }
  }
  // for(int i = 0; i < 10; i++) {
  // 	cout << dp[n][i].fs << " " << dp[n][i].sc << endl;
  // }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#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 = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;

int main() {
  ll n, W;
  cin >> n >> W;
  vector<ll> w(n);
  vector<ll> ww(n);
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
    ww[i] = w[i] - w[0];
  }
  vector<vector<vector<ll>>> dp(
      n + 1, vector<vector<ll>>(n + 1, vector<ll>(600, 0LL)));
  // dp[i][j][k] i番目までを使ってj個使用して重さがkのときの価値の最大値
  for (ll i = 1; i <= n; i++) {
    for (ll j = 1; j <= n; j++) {
      for (ll k = 0; k < 500; k++) {
        if (ww[i - 1] <= k) {
          dp[i][j][k] =
              max(dp[i - 1][j][k], dp[i - 1][j - 1][k - ww[i - 1]] + v[i - 1]);
        } else {
          dp[i][j][k] = dp[i - 1][j][k];
        }
      }
    }
  }

  ll ans = 0LL;
  for (ll i = 0; i <= n; i++) {
    ll k = 0;
    while (W - i * w[0] >= k && k < 500) {
      ans = max(ans, dp[n][i][k]);
      k++;
    }
  }
  // for(int i = 0; i < 10; i++) {
  // 	cout << dp[n][i].fs << " " << dp[n][i].sc << endl;
  // }
  cout << ans << endl;
  return 0;
}
Problem p03732 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const int MAX_N = 100;

int N;
ll W;
ll w[MAX_N + 1], v[MAX_N + 1];
ll dp[MAX_N + 1][3 * (MAX_N - 1) + 1][MAX_N + 1];

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

  cin >> N >> W;

  ll bw;
  cin >> bw;
  cin >> v[1];

  ll sw = 0;

  for (int i = 2; i <= N; i++) {
    ll wgt;
    cin >> wgt;
    w[i] = wgt - bw;
    sw += w[i];
    cin >> v[i];
  }
  dp[1][0][1] = v[1];

  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= sw; j++) {
      for (int k = 0; k <= i; k++) {
        if (j >= w[i + 1] && i >= k + 1) {
          dp[i + 1][j][k + 1] =
              max(dp[i][j - w[i + 1]][k] + v[i + 1], dp[i][j][k + 1]);
        } else if (j >= w[i + 1]) {
          dp[i + 1][j][k + 1] = dp[i][j - w[i + 1]][k] + v[i + 1];
        } else if (i >= k + 1) {
          dp[i + 1][j][k + 1] = dp[i][j][k + 1];
        }
      }
    }
  }

  ll ans = 0;
  for (int j = 0; j <= sw; j++) {
    for (int k = 1; k <= N; k++) {
      if (k * bw + j <= W) {
        ans = max(ans, dp[N][j][k]);
      }
    }
  }

  cout << ans << "\n";

  return 0;
}

Fixed submission:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const int MAX_N = 100;

int N;
ll W;
ll w[MAX_N + 1], v[MAX_N + 1];
ll dp[MAX_N + 1][3 * (MAX_N - 1) + 1][MAX_N + 1];

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

  cin >> N >> W;

  ll bw;
  cin >> bw;
  cin >> v[1];

  ll sw = 0;

  for (int i = 2; i <= N; i++) {
    ll wgt;
    cin >> wgt;
    w[i] = wgt - bw;
    sw += w[i];
    cin >> v[i];
  }
  dp[1][0][1] = v[1];

  for (int i = 1; i < N; i++) {
    for (int j = 0; j <= sw; j++) {
      for (int k = 0; k <= i; k++) {
        if (j >= w[i + 1] && i >= k + 1) {
          dp[i + 1][j][k + 1] =
              max(dp[i][j - w[i + 1]][k] + v[i + 1], dp[i][j][k + 1]);
        } else if (j >= w[i + 1]) {
          dp[i + 1][j][k + 1] = dp[i][j - w[i + 1]][k] + v[i + 1];
        } else if (i >= k + 1) {
          dp[i + 1][j][k + 1] = dp[i][j][k + 1];
        }
      }
    }
  }

  ll ans = 0;
  for (int j = 0; j <= sw; j++) {
    for (int k = 1; k <= N; k++) {
      if (k * bw + j <= W) {
        ans = max(ans, dp[N][j][k]);
      }
    }
  }

  cout << ans << "\n";

  return 0;
}
Problem p03732 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <vector>

long long dp[109][109][309];

int main() {
  long long N, W;
  std::cin >> N >> W;

  std::vector<long long> w_arr(N), v_arr(N);
  for (int i = 0; i < N; i++)
    std::cin >> w_arr[i] >> v_arr[i];

  for (int n = 0; n < N; n++) {
    for (int i = 1; i <= n + 1; i++) {
      for (int w = 0; w < 3 * N; w++) {
        if (w - (w_arr[n] - w_arr[0]) < 0)
          dp[n + 1][i][w] = dp[n][i][w];
        else {
          dp[n + 1][i][w] = std::max(
              dp[n][i][w], dp[n][i - 1][w - (w_arr[n] - w_arr[0])] + v_arr[n]);
        }
      }
    }
  }

  long long ans = 0;
  for (int n = 0; n <= N; n++) {
    long long w = W - n * w_arr[0];
    if (w < 0)
      continue;
    ans = std::max(ans, dp[N][n][w]);
  }

  std::cout << ans << std::endl;

  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>

long long dp[109][109][309];

int main() {
  long long N, W;
  std::cin >> N >> W;

  std::vector<long long> w_arr(N), v_arr(N);
  for (int i = 0; i < N; i++)
    std::cin >> w_arr[i] >> v_arr[i];

  for (int n = 0; n < N; n++) {
    for (int i = 1; i <= n + 1; i++) {
      for (int w = 0; w < 3 * N; w++) {
        if (w - (w_arr[n] - w_arr[0]) < 0)
          dp[n + 1][i][w] = dp[n][i][w];
        else {
          dp[n + 1][i][w] = std::max(
              dp[n][i][w], dp[n][i - 1][w - (w_arr[n] - w_arr[0])] + v_arr[n]);
        }
      }
    }
  }

  long long ans = 0;
  for (int n = 0; n <= N; n++) {
    long long w = W - n * w_arr[0];
    if (w < 0)
      continue;
    if (w > 3 * N)
      w = 3 * N - 1;
    ans = std::max(ans, dp[N][n][w]);
  }

  std::cout << ans << std::endl;

  return 0;
}
Problem p03732 (C++)

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

using namespace std;

typedef long long ll;
#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for (typeof(a) i = (a); i < (n); i++)

int N;
ll W;

int main() {
  cin >> N >> W;
  ll w1, v1;
  cin >> w1 >> v1;

  vector<ll> v[4];
  v[0].push_back(v1);
  ll w_, v_;

  rep(i, N - 1) {
    cin >> w_ >> v_;
    v[w_ - w1].push_back(v_);
  }

  rep(i, N) { sort(v[i].begin(), v[i].end(), greater<ll>()); }

  ll ans = 0;
  rep(n_w1, v[0].size() + 1) {
    rep(n_w2, v[1].size() + 1) {
      rep(n_w3, v[2].size() + 1) {
        rep(n_w4, v[3].size() + 1) {
          w_ = 0;
          v_ = 0;
          rep(i, n_w1) {
            w_ += w1 + 0;
            v_ += v[0][i];
          }
          rep(i, n_w2) {
            w_ += w1 + 1;
            v_ += v[1][i];
          }
          rep(i, n_w3) {
            w_ += w1 + 2;
            v_ += v[2][i];
          }
          rep(i, n_w4) {
            w_ += w1 + 3;
            v_ += v[3][i];
          }
          if (w_ <= W)
            ans = max(ans, v_);
        }
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for (typeof(a) i = (a); i < (n); i++)

int N;
ll W;

int main() {
  cin >> N >> W;
  ll w1, v1;
  cin >> w1 >> v1;

  vector<ll> v[4];
  v[0].push_back(v1);
  ll w_, v_;

  rep(i, N - 1) {
    cin >> w_ >> v_;
    v[w_ - w1].push_back(v_);
  }

  rep(i, 4) { sort(v[i].begin(), v[i].end(), greater<ll>()); }

  ll ans = 0;
  rep(n_w1, v[0].size() + 1) {
    rep(n_w2, v[1].size() + 1) {
      rep(n_w3, v[2].size() + 1) {
        rep(n_w4, v[3].size() + 1) {
          w_ = 0;
          v_ = 0;
          rep(i, n_w1) {
            w_ += w1 + 0;
            v_ += v[0][i];
          }
          rep(i, n_w2) {
            w_ += w1 + 1;
            v_ += v[1][i];
          }
          rep(i, n_w3) {
            w_ += w1 + 2;
            v_ += v[2][i];
          }
          rep(i, n_w4) {
            w_ += w1 + 3;
            v_ += v[3][i];
          }
          if (w_ <= W)
            ans = max(ans, v_);
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p03733 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll t[100010];
int main() {
  int N;
  ll T;
  cin >> N >> T;
  for (int i = 0; i < N; i++)
    cin >> t[i];
  ll ans = T;
  for (int i = 0; i < N - 1; i++) {
    if (t[i + 1] - t[i] < T)
      ans += t[i + 1] - t[i];
    else
      ans += T;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll t[200010];
int main() {
  int N;
  ll T;
  cin >> N >> T;
  for (int i = 0; i < N; i++)
    cin >> t[i];
  ll ans = T;
  for (int i = 0; i < N - 1; i++) {
    if (t[i + 1] - t[i] < T)
      ans += t[i + 1] - t[i];
    else
      ans += T;
  }
  cout << ans << endl;
}
Problem p03733 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 100005
#define trace(x) cout << #x << " = " << x << '\n'
#define trace2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << '\n'
#define trace3(x, y, z)                                                        \
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \
       << z << '\n'
#define sz(x) (int)(x).size()
using namespace std;
struct ii {
  int a, b;
  bool operator<(ii o) const { return tie(a, b) < tie(o.a, o.b); }
};
struct iii {
  int a, b, c;
  bool operator<(iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
long long TC, N, M, K, Q, x, y, z;

long long arr[MAXN], ans;

int main() {
#ifdef FAIRUZI10
  freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
#endif

  scanf("%lld%lld", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &arr[i]);
  }
  long long dari = 0;
  long long sampai = 0;
  ans = 0;
  for (int i = 0; i < N; i++) {
    if (arr[i] <= sampai) {
      sampai = arr[i] + K;
    } else {
      ans += sampai - dari;
      dari = arr[i];
      sampai = arr[i] + K;
    }
  }
  ans += sampai - dari;
  printf("%lld\n", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 200005
#define trace(x) cout << #x << " = " << x << '\n'
#define trace2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << '\n'
#define trace3(x, y, z)                                                        \
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \
       << z << '\n'
#define sz(x) (int)(x).size()
using namespace std;
struct ii {
  int a, b;
  bool operator<(ii o) const { return tie(a, b) < tie(o.a, o.b); }
};
struct iii {
  int a, b, c;
  bool operator<(iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
long long TC, N, M, K, Q, x, y, z;

long long arr[MAXN], ans;

int main() {
#ifdef FAIRUZI10
  freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
#endif

  scanf("%lld%lld", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &arr[i]);
  }
  long long dari = 0;
  long long sampai = 0;
  ans = 0;
  for (int i = 0; i < N; i++) {
    if (arr[i] <= sampai) {
      sampai = arr[i] + K;
    } else {
      ans += sampai - dari;
      dari = arr[i];
      sampai = arr[i] + K;
    }
  }
  ans += sampai - dari;
  printf("%lld\n", ans);

  return 0;
}
Problem p03733 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define LL long long
#define FF(i, a, b) for (int i = a; i <= b; ++i)
#define RR(i, a, b) for (int i = a; i >= b; --i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, b) memset(a, b, sizeof(a))
#define ll rt << 1
#define rr rt << 1 | 1
#define mid int m = (x + ((y - x) >> 1))
#define lson x, m, rt << 1
#define rson m + 1, y, rt << 1 | 1
#define lowbit(x) (x & -x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define fi                                                                     \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout)
using namespace std;

const int N = 1e5 + 10;
const int inf = 1e9;

LL n, t;
LL a[N];
int main() {
#ifndef ONLINE_JUDGE
  // IN;
#endif

  cin >> n >> t;
  LL ans = 0;
  FF(i, 1, n) { cin >> a[i]; }
  FF(i, 2, n) {
    LL cur = a[i] - a[i - 1];
    ans += min(t, cur);
  }
  ans += t;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define LL long long
#define FF(i, a, b) for (int i = a; i <= b; ++i)
#define RR(i, a, b) for (int i = a; i >= b; --i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, b) memset(a, b, sizeof(a))
#define ll rt << 1
#define rr rt << 1 | 1
#define mid int m = (x + ((y - x) >> 1))
#define lson x, m, rt << 1
#define rson m + 1, y, rt << 1 | 1
#define lowbit(x) (x & -x)
#define PB push_back
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define fi                                                                     \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout)
using namespace std;

const int N = 2e6 + 10;
const int inf = 1e9;

LL n, t;
LL a[N];
int main() {
#ifndef ONLINE_JUDGE
  // IN;
#endif

  cin >> n >> t;
  LL ans = 0;
  FF(i, 1, n) { cin >> a[i]; }
  FF(i, 2, n) {
    LL cur = a[i] - a[i - 1];
    ans += min(t, cur);
  }
  ans += t;
  cout << ans << endl;
  return 0;
}
Problem p03733 (C++)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int T;
  cin >> T;

  vector<int> t(T);
  for (int i = 0; i < N; i++)
    cin >> t[i];

  int ans = 0;

  for (int i = 1; i < N; i++)
    ans += t[i] - t[i - 1] < T ? t[i] - t[i - 1] : T;
  ans += T;

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int T;
  cin >> T;

  vector<int> t(N);
  for (int i = 0; i < N; i++)
    cin >> t[i];

  int ans = 0;

  for (int i = 1; i < N; i++)
    ans += t[i] - t[i - 1] < T ? t[i] - t[i - 1] : T;
  ans += T;

  cout << ans << endl;

  return 0;
}
Problem p03733 (C++)

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<double, int> pdbi;
typedef pair<int, pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1 << 30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

// #define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, T;
int t[100000 + 5];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> T;
  rep(i, n) cin >> t[i];
  ll ans = 0;
  rep(i, n - 1) {
    if (t[i + 1] - t[i] >= T)
      ans += T;
    else
      ans += t[i + 1] - t[i];
  }
  cout << ans + T << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<double, int> pdbi;
typedef pair<int, pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1 << 30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

// #define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, T;
int t[200000 + 5];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> T;
  rep(i, n) cin >> t[i];
  ll ans = 0;
  rep(i, n - 1) {
    if (t[i + 1] - t[i] >= T)
      ans += T;
    else
      ans += t[i + 1] - t[i];
  }
  cout << ans + T << endl;
}
Problem p03733 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> P;

ll N;
ll T;
ll t[100100];
ll ans = 0;
int main() {
  cin >> N >> T;
  rep(i, N) { cin >> t[i]; }
  sort(t, t + N);
  rep(i, N - 1) { ans += min(t[i + 1] - t[i], T); }
  ans += T;
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> P;

ll N;
ll T;
ll t[200100];
ll ans = 0;
int main() {
  cin >> N >> T;
  rep(i, N) { cin >> t[i]; }
  sort(t, t + N);
  rep(i, N - 1) { ans += min(t[i + 1] - t[i], T); }
  ans += T;
  cout << ans << endl;
}
Problem p03733 (C++)

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

int main() {
  ll n, t;
  cin >> n >> t;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) b[i] = a[i] + t;
  ll ans;
  ans = b[n] - a[1];
  rep(i, n - 1) {
    if (a[i + 1] > b[i]) {
      ans -= a[i + 1] - b[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n, t;
  cin >> n >> t;
  vector<ll> a(n + 10);
  vector<ll> b(n + 10);
  rep(i, n) cin >> a[i];
  rep(i, n) b[i] = a[i] + t;
  ll ans;
  ans = b[n] - a[1];
  rep(i, n - 1) {
    if (a[i + 1] > b[i]) {
      ans -= a[i + 1] - b[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03733 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int main() {
  int n, T;
  int t[SIZE];
  int ans = 0;

  scanf("%d%d", &n, &T);

  int p = 0;

  for (int i = 0; i < n; i++) {
    scanf("%d", t + i);

    ans += min(T, t[i] + T - p);
    p = t[i] + T;
  }

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

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

int main() {
  int n, T;
  int t[SIZE];
  int ans = 0;

  scanf("%d%d", &n, &T);

  int p = 0;

  for (int i = 0; i < n; i++) {
    scanf("%d", t + i);

    ans += min(T, t[i] + T - p);
    p = t[i] + T;
  }

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

  return 0;
}