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

/*
      Ashraful Islam Paran
      22-August-2020
      19:49:07
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i <= 0; i--)
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\\n"
#define yes cout << "YES\\n"
#define no cout << "NO\\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
  // online submission
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  f(n) { cin >> a[i]; }
  int x = *max_element(a, a + n);
  int cnt{0};
  f(n - 1) {
    if (a[i] > a[i + 1]) {
      cnt += a[i] - a[i + 1];
      swap(a[i], a[i + 1]);
    }
  }
  cout << cnt << endl;

  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\\n";
  return 0;
}

Error: 0

Fixed submission:

// Code by ASIM FOIZE AIMON
// CSE'19;CUET
// avoid copy paste//Hit the frined button
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define precise                                                                \\
  cout.precision(10);                                                          \\
  cout << fixed;
#define endl "\\n"
#define int int64_t
#define ll long long
#define yes printf("YES\\n")
#define no printf("NO\\n")

int32_t main() {
  /*#ifndef ONLINE_JUDGE
      freopen("/media/AIMON/SSDVol/Progs/CodeForces/input.txt", "r", stdin);
      freopen("/media/AIMON/SSDVol/Progs/CodeForces/output.txt", "w", stdout);
  #endif*/
  int a[100001], b[100001], c, d, e, f, m, n, p, x, y, z, t, i, j, k, s = 0;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + t);
  for (i = 0; i < t; i++) {
    if (a[i] < b[i])
      s = s + b[i] - a[i];
    else if (a[i] == b[i])
      s = s + b[t - 1] - a[i];
  }
  cout << s << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long int n, a[10000000], sum = 0;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      sum = sum + (a[i] - a[i + 1]);
      a[i + 1] = a[i];
    }
  }
  cout << sum << "\\n";
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long int n, a[100000000], sum = 0;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      sum = sum + (a[i] - a[i + 1]);
      a[i + 1] = a[i];
    }
  }
  cout << sum << "\\n";
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#define ll long long
using namespace std;
int main() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i];
  vector<ll> pf(n, v[0]);
  for (ll i = 1; i < n; i++) {
    pf[i] = max(pf[i - 1], v[i]);
  }
  ll sum = 0;
  for (ll i = 0; i < n; i++)
    sum += pf[i] - v[i];
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define ll long long
using namespace std;
vector<ll> v;
ll sum = 0;
ll bc(ll ed) {
  ll mx = INT_MIN;
  ll id;
  for (ll i = 0; i <= ed; i++) {
    if (v[i] > mx) {
      mx = v[i];
      id = i;
    }
  }
  return id;
}
void mc(ll ed) {
  ll ct = v[ed];
  for (ll i = ed; i < v.size(); i++) {
    if (v[i] > ct)
      break;
    sum += ct - v[i];
    v[i] = ct;
  }
}
int main() {
  ll n;
  cin >> n;
  v.resize(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i];
  ll id = n;
  while (id != 0) {
    id = bc(id - 1);
    // cout<<id<<endl;
    // cout<<"jj";
    mc(id);
    // cout<<sum<<endl;
  }
  mc(id);
  cout << sum << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int main() {

  long long int N, x, sum = 0, hug = 0;

  cin >> N;

  int i = 0;

  for (int i = 0; i < N; ++i) {
    cin >> x;
    hug = max(x, hug);
    if (x <= hug) {
      sum += hug - x;
    }
  }

  cout << sum << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {

  int N = 0;

  cin >> N;

  string A;

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

  int alen = A.length();
  int sum = 0;
  int com = 0;

  for (int i = 0; i < N - 1; ++i) {
    if (A[i + 1] < A[i]) {
      com = A[i] - A[i + 1];
      sum += com;
      A[i + 1] += com;
    } else {
      continue;
    }
  }

  cout << sum << endl;

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long ans = 0;
  int MaxNum = 0;
  for (int i = 0; i < N; i++) {
    MaxNum = max(MaxNum, A[i]);
    int Bi = MaxNum;
    ans += Bi - A[i];
  }
  cout << ans << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int a[100000000];
  int b[100000000];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  b[0] = a[1] - a[0];
  for (int i = 1; i < n; ++i) {
    b[i] = a[i + 1] - a[i] + b[0];
  }
  int s = 0;
  for (int i = 0; i < n; ++i) {
    s += b[i];
  }
  cout << s << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<long> A;
  A.resize(N);
  for (auto &e : A)
    cin >> e;

  vector<long> B;
  B.resize(N);

  int maxlength = A[0];

  for (int i = 0; i < N; i++) {
    if (A[i] > maxlength) {
      maxlength = A[i];
      B[i] = maxlength;
    } else {
      B[i] = maxlength;
    };
  }

  long total = 0;
  for (int i = 0; i < N; i++)
    total += (B[i] - A[i]);

  cout << total << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<long> A;
  A.resize(N);
  for (auto &e : A)
    cin >> e;

  vector<long> B;
  B.resize(N);

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (A[i] + B[i] > A[j] + B[j]) {
        B[j] = A[i] + B[i] - A[j];
      }
    }
  }

  long total = 0;
  for (int i = 0; i < N; i++)
    total += B[i];

  cout << total << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  long long int answer = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H.at(i) >= H.at(i + 1)) {
      answer += H.at(i) - H.at(i + 1);
      H.at(i + 1) = H.at(i);
    } else if (H.at(i) < H.at(i + 1)) {
      continue;
    }
  }

  cout << answer << endl;
}

Error: TLE

Fixed submission:

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

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

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

  int count = 0;

  for (int i = 0; i < N - 1; i++) {
    int &a = A.at(i + 1);
    while (A.at(i) > a) {
      count++;
      a++;
    }
  }

  cout << count << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
struct node {
  long long num;
  long long id;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a;
  cin >> a;
  node MAX;
  MAX.num = 0;
  MAX.id = 0;
  node k[a];
  long long ans = 0;
  long long maxv = 0;
  for (int i = 0; i < a; i++) {
    cin >> k[i].num;
    if (k[i].num > maxv) {
      maxv = k[i].num;
    } else if (k[i].num < maxv) {
      ans += maxv - k[i].num;
      k[i].num = maxv;
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
struct node {
  long long num;
  long long id;
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long a;
  cin >> a;
  node MAX;
  MAX.num = 0;
  MAX.id = 0;
  node k[a];
  long long ans = 0;
  for (int i = 0; i < a; i++) {
    cin >> k[i].num;
    k[i].id = i;
  }
  while (a > 0) {
    for (int j = 0; j < a; j++) {
      if (MAX.num < k[j].num) {
        MAX.num = k[j].num;
        MAX.id = j;
      }
    }
    for (int j = MAX.id + 1; j < a; j++) {
      ans += MAX.num - k[j].num;
    }
    a = MAX.id;
    MAX.num = 0;
    MAX.id = 0;
  }
  cout << ans;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 200010;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int n, m, a[maxn];
string s, ss;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  ll cnt = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    if (a[i] < a[i - 1])
      cnt += (ll)a[i - 1] - (ll)a[i], a[i] += (ll)a[i - 1] - (ll)a[i];
  cout << cnt << "\\n";
}


Error: 0

Fixed submission:

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 100010;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int n, m, a[maxn];
string s, ss;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  ll cnt = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    if (a[i] < a[i - 1])
      cnt += (ll)a[i - 1] - (ll)a[i], a[i] += (ll)a[i - 1] - (ll)a[i];
  cout << cnt << "\\n";
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int N;
  int A[200000];
  int max = 0;
  long long total = 0LL;
  cin >> N;
  for (int a = 0; a < N; a++)
    cin >> A[a];
  max = A[0];
  for (int i = 1; i < N; i++) {
    if (max < A[i])
      max = A[i];

    total += max - A[i];
  }
  cout << total;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, a[100], fumi = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int m = 1; m < n; m++) {
    for (int i = 0; i < n; i++) {
      if (a[m - 1] > a[m]) {
        a[m] = a[m] + 1;
        fumi = fumi + 1;
      } else {
        continue;
      }
    }
  }
  cout << fumi;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long int> A(N);
  for (int loop = 0; loop < N; loop++) {
    cin >> A[loop];
  }

  long int max = A[0];
  long int sum = 0;
  for (int loop = 1; loop < N; loop++) {
    if (A[loop] < max) {
      sum += max - A[loop];
    } else if (A[loop] > max) {
      max = A[loop];
    }
  }

  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  vector<long int> A(N);

  cin >> N;
  for (int loop = 0; loop < N; loop++) {
    cin >> A[loop];
  }

  long int max = A[0];
  long int sum = 0;
  for (int loop = 1; loop < N; loop++) {
    if (A[loop] < max) {
      sum += max - A[loop];
    } else if (A[loop] > max) {
      max = A[loop];
    }
  }

  cout << sum << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int N;
ll A[200010];

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];

  ll ans = 0;
  ll max_value = A[0];
  rep(i, N - 1) {
    if (max_value > A[i + 1]) {
      ans += max_value - A[i + 1];
    } else {
      max_value = A[i + 1];
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int N;
ll A[100010];

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];

  ll ans = 0;
  ll max_value = A[0];
  rep(i, N - 1) {
    if (A[i] > A[i + 1]) {
      ans += max_value - A[i + 1];
    } else {
      max_value = A[i + 1];
    }
  }
  cout << ans << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sd(x) scanf("%lf", &x)
#define l0(i, n) for (ll i = 0; i < n; i++)
#define MAX 100005
#define maxn 200002
#define pb push_back
#define mk make_pair
#define endl "\\n"
#define INF 1000000000
#define MOD 1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // CODE TONOY
  // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  ll ans = 0;
  for (int i = 1; i < N; i++) {
    if (A[i] < A[i - 1]) {
      ans += A[i - 1] - A[i];
      A[i] = A[i - 1];
    }
  }

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


Error: TLE

Fixed submission:

/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sd(x) scanf("%lf", &x)
#define l0(i, n) for (ll i = 0; i < n; i++)
#define MAX 100005
#define maxn 200002
#define pb push_back
#define mk make_pair
#define endl "\\n"
#define INF 1000000000
#define MOD 1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // CODE TONOY
  // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      ans = ans + a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
    cerr << imie(a[i]) imie(a[i - 1]) imie(ans) << endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;

int n;
ll a[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll sum = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      sum += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << sum;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
const int N = 2e5 + 10;
int n;
int a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int t = *max_element(a + 1, a + n + 1),
      s = max_element(a + 1, a + n + 1) - &a[0];
  int sum = 0;
  if (t == 1) {
    for (int i = 2; i <= n; i++)
      sum += 5 - a[i];

    cout << sum;
    return 0;
  }
  for (int i = 1; i <= t - 1; i++) {
    if (a[i - 1] > a[i]) {
      sum += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  for (int i = t; i <= n; i++) {
    if (t > a[i]) {
      sum += t - a[i];
      a[i] = t;
    }
  }

  cout << sum;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  ll ans = 0, m = 0;
  cin >> n;
  ll a[n + 10];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (a[i] > a[m])
      m = i;
    else
      ans += a[m] - a[i];
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll a[200010];
int n;
ll ans = 0;

void sol(int right, int mi) {
  if (right <= 0)
    return;
  for (int i = mi; i < right; i++)
    ans += a[mi] - a[i];
  right = mi;
  mi = 0;
  for (int i = 0; i < right; i++)
    if (a[i] > a[mi])
      mi = i;
  sol(right, mi);
}

int main() {
  int mi = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    if (a[i] > a[mi])
      mi = i;
  sol(n, mi);
  cout << ans << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using lint = long long;

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

  int n;
  cin >> n;
  lint ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      ans += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << ans << "\\n";
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long;

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

  int N, M;
  cin >> N >> M;
  int sx, sy, ex, ey;
  cin >> sx >> sy >> ex >> ey;
  sx--, sy--, ex--, ey--;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  deque<pair<pair<int, int>, int>> dq;
  dq.push_back({{sx, sy}, 0});
  vector<vector<int>> dist(N, vector<int>(M, -1));
  dist[sx][sy] = 0;
  while (!dq.empty()) {
    int x = dq.front().first.first;
    int y = dq.front().first.second;
    int d = dq.front().second;
    dq.pop_front();
    if (dist[x][y] != d) {
      continue;
    }
    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int nx = x + i, ny = y + j;
        if (abs(i) + abs(j) == 1 && 0 <= nx && nx < N && 0 <= ny && ny < M &&
            A[nx][ny] != '#') {
          if (dist[nx][ny] == -1 || dist[nx][ny] > dist[x][y]) {
            dist[nx][ny] = dist[x][y];
            dq.push_front({{nx, ny}, dist[nx][ny]});
          }
        }
        if (0 <= nx && nx < N && 0 <= ny && ny < M && A[nx][ny] != '#') {
          if (dist[nx][ny] == -1 || dist[nx][ny] > dist[x][y] + 1) {
            dist[nx][ny] = dist[x][y] + 1;
            dq.push_back({{nx, ny}, dist[nx][ny]});
          }
        }
      }
    }
  }
  cout << dist[ex][ey] << "\\n";
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long int N, sum = 0, max;
  cin >> N;
  vector<long int> a(N);
  rep(i, N) cin >> a.at(i);
  max = a.at(0);
  rep(i, N - 1) {
    if (max <= a.at(i + 1))
      max = a.at(i + 1);
    else
      sum += (max - a.at(i + 1));
  }
  cout << sum << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  long int N, x, sum = 0;
  cin >> N;
  vector<long int> a(N);
  rep(i, N) cin >> a.at(i);
  x = max(a.at(0), a.at(1));
  rep(i, N - 1) {
    if (x <= a.at(i + 1))
      x = max(x, a.at(i + 1));
    else if (x > a.at(i + 1))
      sum += (x - a.at(i + 1));
  }
  cout << sum << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using ll = long long;
using namespace std;

int main() {
  ll N;
  ll count = 0;
  cin >> N;
  vector<ll> A(N);
  ll max = 0;
  vector<ll> dis(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (ll k = 1; k <= N; k++) {
    if (max < A[k - 1]) {
      max = A[k - 1];
    }
    dis[k - 1] = max - A[k - 1];
    count = count + dis[k - 1];
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using ll = long long;
using namespace std;

int main() {
  ll N;
  ll count = 0;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  vector<ll> max(N);
  vector<ll> dis(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (ll k = 1; k <= N; k++) {
    max[k - 1] = A[k - 1];
    for (ll j = 0; j <= k - 1; j++) {
      if (max[k - 1] < A[j]) {
        max[k - 1] = A[j];
      }
    }
    dis[k - 1] = max[k - 1] - A[k - 1];
    count = count + dis[k - 1];
  }
  cout << count << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

// Contest No.: ABC176
// Problem No.: C
// Solver:      Jinmin Goh
// Date:        20200822

#include <algorithm>
#include <array>
#include <atomic>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;

int nums[200010];

int main() {
  long long int n, ans = 0;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &nums[i]);
  }

  int curMin = nums[0];
  for (int i = 0; i < n; i++) {
    if (nums[i] > curMin) {
      curMin = nums[i];
    } else {
      ans += curMin - nums[i];
    }
  }
  printf("%lld", ans);
  return 0;
}

Error: -11

Fixed submission:

// Contest No.: ABC176
// Problem No.: D
// Solver:      Jinmin Goh
// Date:        20200822

#include <algorithm>
#include <array>
#include <atomic>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;

int nums[200010];

int main() {
  int t;
  scanf("%d", &t);
  for (int _ = 0; _ < t; _++) {
    int n, ans;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", nums[100010]);
    }

    printf("%d", ans);
  }

  return 0;
}