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

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define forn(n1, n2) for (ll i = n1; i < n2; i++)
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define en "\\n"
#define mod 1e6 + 3
#define f first
#define s second
using namespace std;
ll i, n, m, x, y, z, j, k, l, mn = LLONG_MAX, mx = 0, c, a[100005], r, cnt = 0,
                              sum = 0;
string str;
char ch;
set<ll> s;
map<ll, ll> mp;
vector<vector<ll>> g;
vector<ll> v;
void swap(int *xp, int *yp) {
  int temp = *xp;
  *xp = *yp;
  *yp = temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  ll a[n];
  forn(0, n) cin >> a[i];
  ll mx = 0, step = 0;
  forn(0, n) {
    mx = max(mx, a[i]);
    step += mx - a[i];
  }
  cout << step;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define forn(n1, n2) for (ll i = n1; i < n2; i++)
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define en "\\n"
#define mod 1e6 + 3
#define f first
#define s second
using namespace std;
ll i, n, m, x, y, z, j, k, l, mn = LLONG_MAX, mx = 0, c, a[100005], r, cnt = 0,
                              sum = 0;
string str;
char ch;
set<ll> s;
map<ll, ll> mp;
vector<vector<ll>> g;
vector<ll> v;
void swap(int *xp, int *yp) {
  int temp = *xp;
  *xp = *yp;
  *yp = temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  forn(0, n) cin >> a[i];
  ll mx = 0, step = 0;
  forn(0, n) {
    mx = max(mx, a[i]);
    step += mx - a[i];
  }
  cout << step << en;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

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


Error: -11

Fixed submission:

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

int main() {

  ll n;
  cin >> n;
  vector<ll> x;
  rep(i, n) { cin >> x[i]; }
  ll ans = 0;
  rep(i, n) {
    if (x[i] > x[i + 1]) {
      ans += x[i] - x[i + 1];
      x[i] = x[i + 1];
    } else {
      continue;
    }
  }

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

#include <bits/stdc++.h>
// #include <numeric>//int sum = accumulate(v.begin(), v.end(), 0)
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <math.h>    //pow(x,y)=x^y
#define rep(init, i, n) for (int i = init; i < (n); i++)
#define ll long long
using namespace std;

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

  vector<ll> a(n);
  vector<ll> b(n);

  rep(0, i, n) { cin >> a.at(i); }
  ll temp_max = 0;
  ll index_oldmax = 0;
  rep(0, i, n) {
    if (a.at(i) > temp_max) {
      rep(index_oldmax, j, i) {
        b.at(j) = (temp_max - a.at(j));
        a.at(j) = temp_max;
        // cout<<"i="<<i<<endl;//
        // cout<<"j="<<j<<endl;//
        // cout<<"aj"<<a.at(j)<<endl;//
        // cout<<"bj"<<b.at(j)<<endl;//
      }
      temp_max = a.at(i);
      index_oldmax = i;
    }
    if (i == n - 1) {
      rep(index_oldmax, j, i + 1) {
        b.at(j) = (temp_max - a.at(j));
        a.at(j) = temp_max;
        // cout<<"i="<<i<<endl;//
        // cout<<"j="<<j<<endl;//
        // cout<<"bj"<<b.at(j)<<endl;//
      }
    }
  }
  /*rep(0,i,n){
  cout<<" a.at(i)="<<a.at(i);//
  //
  }*/
  ll sum = 0;
  rep(0, i, n) { sum += b.at(i); }
  cout << sum;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <bits/stdc++.h>
#include <math.h>  //pow(x,y)=x^y
#include <numeric> //int sum = accumulate(v.begin(), v.end(), 0)
#define rep(init, i, n) for (int i = init; i < (n); i++)
#define ll long long
using namespace std;

int main() {
  int n;
  vector<int> a(n);
  vector<int> b(n);

  cin >> n;
  rep(0, i, n) { cin >> a.at(i); }
  reverse(a.begin(), a.end());
  rep(0, i, n) { cout << a.at(i) << endl; }
  // 後ろから見ていく
  rep(0, i, n - 1) {
    if (a.at(i) < a.at(i + 1)) {
      rep(0, j, i + 1) {
        b.at(j) = a.at(i + 1) - a.at(j);
        a.at(j) = a.at(i + 1);
      }
    }
  }
  int sum = accumulate(b.begin(), b.end(), 0);

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

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m) {
  if ((a + b) >= m)
    return (a + b) % m;
  return a + b;
}

inline ll mul(ll a, ll b, ll m) {
  if ((a * b) < m)
    return a * b;
  return (a * b) % m;
}

ll power(ll x, ll y, ll m) {
  ll res = 1;
  x = x % m;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % m;
    y = y >> 1;
    x = (x * x) % m;
  }
  return res;
}

void solve() {
  int n;
  cin >> n;
  vl a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll M = a[0], ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] < M) {
      ans += M - a[i];
    } else {
      M = max(M, a[i]);
    }
  }

  cout << ans;
}

int main() {
  fastio;
  int t;
  t = 1;
  // cin >> t;
  // int test=t;

  while (t-- > 0) {
    // cout<<"Case #"<<(test-t)<<": ";
    solve();
    cout << newl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int a[200005];
int main() {
  ll n, m, i, j, t;
  while (cin >> n) {
    for (i = 1; i <= n; i++) {
      cin >> a[i];
    }
    ll ans = 0;
    for (i = 1; i < n; i++) {
      if (a[i] > a[i + 1]) {
        ans += a[i] - a[i + 1];
        a[i + 1] = a[i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, t, a[100005];
  while (cin >> n) {
    for (i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    for (i = 1; i < n; i++) {
      if (a[i] > a[i + 1]) {
        ans += a[i] - a[i + 1];
        a[i + 1] = a[i];
      }
    }
    cout << ans << 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<long long> A(N);

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

  long long cnt = 0;

  for (int i = 0; i < (N - 1); i++) {
    if (A.at(i) > A.at(i + 1)) {
      cnt += (A.at(i) - A.at(i + 1));
      A.at(i + 1) = A.at(i);
    }
  }

  cout << cnt << endl;
}


Error: TLE

Fixed submission:

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

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

  vector<long long> A(N);

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

  long long cnt = 0;

  for (int i = 0; i < N; i++) {
    for (int k = i + 1; k < N; k++) {
      if (A.at(i) - A.at(k) > 0) {
        cnt += (A.at(i) - A.at(k));
        A.at(k) = A.at(i);
      }
    }
  }

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

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

int main() {
  int N;
  cin >> N;
  long long 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 << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  long long ans = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  auto search_end = A.end();
  while (search_end != A.begin()) {
    auto result = max_element(A.begin(), search_end);
    for (auto itr = result; itr != search_end; itr++) {
      ans += *result - *itr;
    }
    search_end = result;
  }
  cout << ans << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int M = 1e6 + 5;
int a[M];
int main() {
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] >= a[i - 1])
      continue;
    int id = a[i - 1] - a[i];
    a[i] += id;
    ans += id;
  }
  printf("%lld", ans);
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int M = 1e5 + 5;
int a[M];
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] >= a[i - 1])
      continue;
    int id = a[i - 1] - a[i];
    a[i] += id;
    ans += id;
  }
  printf("%d", ans);
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long N = 0, sum = 0;
  long long a[200001];
  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 + 1] < a[i]) {
      sum += (a[i] - a[i + 1]);
      a[i + 1] = a[i];
    }
  }
  cout << sum;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N = 0, sum = 0;
  int a[N];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  cout << endl;
  for (int i = 0; i < N - 1; i++) {
    if (a[i + 1] < a[i]) {
      sum += (a[i] - a[i + 1]);
      a[i + 1] = a[i];
    }
  }
  cout << sum;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<long long> v;
  long long a;
  long long z = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    if (i >= 1 && v.at(i) < v.at(i - 1)) {
      z += v.at(i - 1) - v.at(i);
      v.at(i) = v.at(i - 1);
    }
  }
  cout << z << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<long long> v;
  long long a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  reverse(v.begin(), v.end());
  long long z = 0;
  for (int i = 0; i < n; i++) {
    auto it = v.begin() + i;
    long long x = *max_element(it, v.end());
    z += x - v.at(i);
  }
  cout << z << endl;

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

#define boost
#ifdef boost
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#endif
#include <bits/stdc++.h>
#define int long long
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
#define __ read()
using namespace std;
const int maxn(2e5 + 5);
void rda(int *a, int n) {
  for (int i = 1; i <= n; ++i)
    a[i] = __;
}
void print(int *a, int n) {
  for (int i = 1; i <= n; ++i)
    printf("%lld ", a[i]);
  puts("");
}
int n, a[maxn];
signed main() {
  n = __;
  rda(a, n);
  int 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;
}


Error: WA

Fixed submission:

#define boost
#ifdef boost
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#endif
#include <bits/stdc++.h>
#define int long long
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
#define __ read()
using namespace std;
const int maxn(1e5 + 5);
void rda(int *a, int n) {
  for (int i = 1; i <= n; ++i)
    a[i] = __;
}
void print(int *a, int n) {
  for (int i = 1; i <= n; ++i)
    printf("%lld ", a[i]);
  puts("");
}
int n, a[maxn];
signed main() {
  n = __;
  rda(a, n);
  int 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;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, cnt = 0;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      j = a[i] - a[i + 1];
      cnt = cnt + j;
      a[i + 1] = a[i + 1] + j;
    }
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, temp, cnt = 0;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n - i - 1; j++) {
      if (a[j] > a[j + 1]) {
        temp = a[j];
        a[j] = a[j + 1];
        a[j + 1] = temp;
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define imp()                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define pb push_back
#define endl "\\n"
#define lli long long int
#define ll long long
#define f(i, a, b) for (i = (int)a; i < (int)b; i++)
lli gccd(lli a, lli b) {
  if (b == 0)
    return a;
  // else
  return (b, a % b);
}
lli sum(string str) {
  lli s = 0;
  for (lli i = 0; i < str.size(); i++) {
    s += str[i] - '0';
  }
  return s;
}
int main() {
  // your code goes here
  imp();
  int n;
  cin >> n;
  lli arr[n];
  lli c = 0;
  lli maxx = INT_MIN;
  lli pos = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i]; // maxx=max(arr[i],maxx);
  }
  maxx = arr[0];
  for (int i = 1; i < n; i++) {
    if (arr[i] < maxx)
      c += maxx - arr[i];
    else if (arr[i] > maxx)
      maxx = arr[i];
  }
  cout << c << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define imp()                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define pb push_back
#define endl "\\n"
#define lli long long int
#define ll long long
#define f(i, a, b) for (i = (int)a; i < (int)b; i++)
lli gccd(lli a, lli b) {
  if (b == 0)
    return a;
  // else
  return (b, a % b);
}
lli sum(string str) {
  lli s = 0;
  for (lli i = 0; i < str.size(); i++) {
    s += str[i] - '0';
  }
  return s;
}
int main() {
  // your code goes here
  imp();
  int n;
  cin >> n;
  lli arr[n];
  lli c = 0;
  lli maxx = INT_MIN;
  lli pos = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  for (int i = n - 1; i > 0; i--) {
    maxx = arr[i];
    for (int j = i - 1; j >= 0; j--) {
      if (arr[j] >= maxx)
        maxx = arr[j];
    }

    c += maxx - arr[i];
  }
  cout << c << "\\n";
  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> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int64_t sum = 0;
  for (int i = 1; i < N; i++) {
    if (vec.at(i - 1) > vec.at(i)) {
      sum += (vec.at(i - 1) - vec.at(i));
      vec.at(i) = vec.at(i - 1);
    }
  }
  cout << sum << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int sum = 0;
  for (int i = 1; i < N + 1; i++) {
    if (vec.at(i - 1) > vec.at(i)) {
      sum += (vec.at(i - 1) - vec.at(i));
      vec.at(i) = vec.at(i - 1);
    }
  }
  cout << sum << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, chukan = 0;
  long long sum = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  for (int i = 0; i < N; i++) {
    chukan = max(chukan, vec[i]);
    sum += chukan - vec[i];
  }
  cout << sum;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)


Fixed submission:

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

int main() {
  int N, sum = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (vec.at(i) > vec.at(i + 1)) {
      sum += vec.at(i) - vec.at(i + 1);
      vec.at(i + 1) = vec.at(i);
    }
  }
  cout << sum;
  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];
  }
  int max = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (max < A[i]) {
      max = A[i];
    }
    sum += max - A[i];
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  vector<int> A(n);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int max1 = 0;
  for (int i = 0; i < n; i++) {
    if (max1 < A[i]) {
      max1 = A[i];
    }
  }
  int count = -1;
  for (int i = 0; i < n; i++) {
    count++;
    if (A[i] == max1) {
      break;
    }
  }
  int max2 = 0;
  for (int i = 0; i < count; i++) {
    if (max2 < A[i]) {
      max2 = A[i];
    }
  }
  int sum1 = 0;
  for (int i = 0; i < count; i++) {
    sum1 += (max2 - A[i]);
  }
  int sum2 = 0;
  for (int i = count; i < n; i++) {
    sum2 += (max1 - A[i]);
  }
  cout << sum1 + sum2 << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

ll a[200005];

int main() {
  int n;
  cin >> n;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll res = 0;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      res += (1LL * (a[i - 1] - a[i]));
      //			cout<<res<<endl;
      a[i] += (1LL * (a[i - 1] - a[i]));
    }
  }
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

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

ll a[100005];

int main() {
  int n;
  cin >> n;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll res = 0;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      res += ((a[i - 1] - a[i]));
      //			cout<<res<<endl;
      a[i] += ((a[i - 1] - a[i]));
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long int ll;
const ll maxn = 1e6 + 8;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  ll i, a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll s = 0;
  for (i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      s = s + (a[i] - a[i + 1]);
      a[i + 1] = a[i];
    }
  }
  cout << s;
  cerr << "\\nTime elapsed:" << 1000 * clock() / CLOCKS_PER_SEC << "ms\\n";
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long int ll;
const ll maxn = 1e6 + 8;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  ll i, a[i];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll s = 0;
  for (i = 0; i < n - 1; i++) {
    if (a[i] > a[i + 1]) {
      s = s + (a[i] - a[i + 1]);
      a[i + 1] = a[i];
    }
  }
  cout << s << "\\n";
  cerr << "\\nTime elapsed:" << 1000 * clock() / CLOCKS_PER_SEC << "ms\\n";
  return 0;
}