alexjercan/bugnet huggingface dataset:
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define fix(a)                                                                 \\
  cout << setprecision(a);                                                     \\
  cout << fixed;
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define clr(a) memset(a, 0, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((int)(x).size())
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;

int main() {
  fast;
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int del = 0;
    if (arr[i] > arr[i + 1])
      del = arr[i] - arr[i + 1];
    ans += del;
    arr[i + 1] += del;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define fix(a)                                                                 \\
  cout << setprecision(a);                                                     \\
  cout << fixed;
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define clr(a) memset(a, 0, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((int)(x).size())
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;

int main() {
  fast;
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  ll ans = 0;
  for (int it = n - 1; it > 0; it--) {
    int idx = max_element(arr.begin(), arr.begin() + (it + 1)) - arr.begin();
    while (it != idx) {
      ans += arr[idx] - arr[it];
      it--;
    }
  }
  cout << ans;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll long long int

int main() {
  FAST;
  ll b, d = 0, e;
  int a, c = 1;
  cin >> a;
  int k[a + 5];
  k[0] = 0;
  while (c <= a) {
    cin >> k[c];
    if (k[c] < k[c - 1]) {
      d = d + k[c - 1] - k[c];
      k[c] = k[c - 1];
    }
    c++;
  }
  cout << d;
}


Error: WA

Fixed submission:

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

#define FAST                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll long long int

int main() {
  FAST;
  ll a, b, c = 1, d = 0, e;
  cin >> a;
  int k[a];
  k[0] = 0;
  while (c <= a) {
    cin >> k[c];
    if (k[c] < k[c - 1]) {
      d = d + k[c - 1] - k[c];
      k[c] = k[c - 1];
    }
    c++;
  }
  cout << d;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  long long X;
  X = 0;
  for (int i = 1; i < N; i++) {
    if (V.at(i - 1) > V.at(i)) {
      X += V.at(i - 1) - V.at(i);
      V.at(i) += V.at(i - 1) - V.at(i);
    } else {
      continue;
    }
  }
  cout << X << endl;
}

Error: 0

Fixed submission:

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

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N, 0);
  B.at(0) = 0;
  long long total = 0;
  for (int i = 0; i < (N - 1); i++) {
    int b = ((A.at(i) - A.at(i + 1)) + B.at(i));
    if (b < 0) {
      b = 0;
    }
    B.at(i + 1) = b;
    total = total + B.at(i + 1);
  }
  cout << total << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N, 0);
  B.at(0) = 0;
  int total = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < 10000000; j++) {
      B.at(i + 1) = j;
      if ((A.at(i) + B.at(i)) <= (A.at(i + 1) + B.at(i + 1))) {
        break;
      }
    }
    total = total + B.at(i + 1);
  }
  cout << total << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\\n'
#define ll long long
#define modd(a, b) ((a + 2 * b) % b)
#define debug(a) cout << #a << ": " << (a) << "\\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#define ffe                                                                    \\
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

int main() {
  ioso
#ifndef ONLINE_JUDGE
      ffe
#endif
          ll n;
  cin >> n;
  int a[200010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll s = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      // cout << a[i-1]-a[i] << endl;
      s += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << s << endl;
}

Error: WA

Fixed submission:

/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include <bits/stdc++.h>
using namespace std;

#define endl '\\n'
#define ll long long
#define modd(a, b) ((a + 2 * b) % b)
#define debug(a) cout << #a << ": " << (a) << "\\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#define ffe                                                                    \\
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

int main() {
  ioso
#ifndef ONLINE_JUDGE
      ffe
#endif
          ll n;
  cin >> n;
  int a[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll s = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      // cout << a[i-1]-a[i] << endl;
      s += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << s << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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


Error: WA

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long sa, sum;
  sa = 0;
  sum = 0;
  cin >> N;
  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]) {
      sa = a[i - 1] - a[i];
      a[i] = a[i] + sa;
      sum = sum + sa;
    }
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long sa, sum;
  sa = 0;
  sum = 0;
  vector<int> a(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < N; i++) {
    if (a[i - 1] > a[i]) {
      sa = a[i - 1] - a[i];
      a[i] = a[i] + sa;
      sum = sum + sa;
    }
  }
  cout << sum << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n;
int a[2000005];
int x = 0;
long long ans = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      ans += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  printf("%lld", ans);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int x = 0;
int ans = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      ans += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  printf("%d", ans);
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll arr[1000000];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (arr[i] > arr[i + 1]) {
      ans += arr[i] - arr[i + 1];
      arr[i + 1] = arr[i];
    }
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll arr[100000];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (arr[i] > arr[i + 1]) {
      ans += arr[i] - arr[i + 1];
      arr[i + 1] = arr[i];
    }
  }
  cout << ans;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  long long count;
  cin >> N;
  vector<int> a(N);
  count = 0;

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (i > 0) {
      if (a.at(i - 1) > a.at(i)) {
        count += a.at(i - 1) - a.at(i);
        a.at(i) = a.at(i - 1);
      }
    }
  }
  cout << count << endl;
}

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


Fixed submission:

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

int main() {
  int N, count;
  cin >> N;
  vector<int> a;
  count = 0;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll t, n, k, a[maxn], res;
int main() {
  // freopen("in.txt","r",stdin);
  cin >> t;
  for (int i = 0; i < t; i++)
    cin >> a[i];
  for (int i = 0; i < t - 1; i++) {
    if (a[i] > a[i + 1]) {
      res += a[i] - a[i + 1];
      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;
const ll maxn = 1e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll t, n, k, a[maxn], res;
int main() {
  // freopen("in.txt","r",stdin);
  cin >> t;
  for (int i = 0; i < t; i++)
    cin >> a[i];
  for (int i = 0; i < t - 1; i++) {
    if (a[i] > a[i + 1]) {
      res += a[i] - a[i + 1];
      a[i + 1] = a[i];
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

long long arr[200005];
int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);

  int n, f;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  f = arr[0];
  long long suma = 0, sumb = 0;
  for (int i = 1; i < n; i++) {
    if (arr[i] < f) {
      suma += f - arr[i];
    } else if (arr[i] > f) {
      f = arr[i];
    }
  }
  cout << suma << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);

  int n, f;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  f = arr[0];
  int suma = 0, sumb = 0;
  for (int i = 1; i < n; i++) {
    if (arr[i] < f) {
      suma += f - arr[i];
    } else if (arr[i] > f) {
      f = arr[i];
    }
  }
  f = arr[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    if (arr[i] < f) {
      sumb += f - arr[i];
    } else if (arr[i] > f) {
      f = arr[i];
    }
  }
  if (suma > sumb) {
    cout << sumb << endl;
  } else {
    cout << suma << endl;
  }
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int64_t u;
  int64_t sum = 0;
  int A[200000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (N == 1) {
    cout << sum << endl;
  } else {
    for (int i = 0; i < N - 1; i++) {
      int s = i + 1;
      // cout<<A[i]<<A[s]<<endl;
      if (A[i] > A[s]) {
        u = A[i] - A[s];
        A[s] = A[i];
        sum += u;
        // cout << u <<endl;
      }
    }
    cout << sum << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int64_t u;
  int64_t sum = 0;
  int A[100000000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (N == 1) {
    cout << sum << endl;
  } else {
    for (int i = 0; i < N - 1; i++) {
      int s = i + 1;
      // cout<<A[i]<<A[s]<<endl;
      if (A[i] > A[s]) {
        u = A[i] - A[s];
        A[s] = A[i];
        sum += u;
        // cout << u <<endl;
      }
    }
    cout << sum << endl;
  }
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

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

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

  for (int i = 0; i < N - 1; i++) {
    if (height.at(i) > height.at(i + 1)) {
      sum += height.at(i) - height.at(i + 1);
      height.at(i + 1) = height.at(i);
    }
  }
  cout << sum;
}

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> height(N);
  for (int i = 0; i < N; i++) {
    cin >> height.at(i);
  }
  int sum = 0;

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

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

int main() {
  long long a[200005];
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  long long Max = -1;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    Max = max(a[i], Max);
    ans += abs(Max - a[i]);
  }
  cout << ans;
}

Error: WA

Fixed submission:

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

int main() {
  long long a[100005];
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long Max = -1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    Max = max(a[i], Max);
    ans += Max - a[i];
  }
  cout << ans;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll N;
  ll sum = 0, mx;
  vi A(300000);
  cin >> N;
  rep(i, N) cin >> A[i];
  mx = A[0];
  rep(i, N) {
    if (mx > A[i])
      sum += mx - A[i];
    if (A[i] > mx)
      mx = A[i];
  }
  cout << sum << endl;
}


Error: 0

Fixed submission:

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

int main() {
  ll N;
  ll sum = 0, mx;
  vi A(30000);
  cin >> N;
  rep(i, N) cin >> A[i];
  mx = A[0];
  rep(i, N) {
    if (mx > A[i])
      sum += mx - A[i];
    if (A[i] > mx)
      mx = A[i];
  }
  cout << sum << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  long long s = 0, i, n, a[200000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      s += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << s;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  int a[100], i, j, n, k = 0, tem;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (a[i] > a[j]) {
        tem = a[i];
        a[i] = a[j];
        a[j] = tem;
        k++;
      }
    }
  }
  printf("%d\\n", k);

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

#include <iostream>
#include <vector>
using namespace std;
// 5
// 2 1 5 4 3
typedef long long ll;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

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

  // for (int i = 0; i < N; i++) cout << A[i] << endl;
  std::cout << sum << std::endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
// 5
// 2 1 5 4 3
typedef long long ll;
int main() {
  int N;
  vector<ll> A(N);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

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

  // for (int i = 0; i < N; i++) cout << A[i] << endl;
  std::cout << sum << std::endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int64_t u;
  int64_t sum = 0;
  int A[1000000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (N == 1) {
    cout << sum << endl;
  } else {
    for (int i = 0; i < N - 1; i++) {
      int s = i + 1;
      // cout<<A[i]<<A[s]<<endl;
      if (A[i] > A[s]) {
        u = A[i] - A[s];
        A[s] = A[i];
        sum += u;
        // cout << u <<endl;
      }
    }
    cout << sum << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int64_t u;
  int sum = 0;
  int A[100000000];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (N == 1) {
    cout << sum << endl;
  } else {
    for (int i = 0; i < N - 1; i++) {
      int s = i + 1;
      // cout<<A[i]<<A[s]<<endl;
      if (A[i] > A[s]) {
        u = A[i] - A[s];
        A[s] = A[i];
        sum += u;
        // cout << u <<endl;
      }
    }
    cout << sum << endl;
  }
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long N, ans = 0;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  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;
}

Error: TLE

Fixed submission:

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

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

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

  int sum = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 0; Ah[i] < Ah[i - 1]; j++) {
      humidai[i] += 1;
      Ah[i] = A[i] + humidai[i];
    }
    sum += humidai[i];
  }
  cout << sum << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long int ll;
typedef long unsigned lu;
typedef vector<ll> v;
typedef pair<ll, ll> p;
typedef vector<p> vp;
#define rep(i, j, k) for (ll i = j; i < k; i++)
#define repr(i, j, k) for (ll i = k; i >= j; i--)
#define read(a, n) rep(i, 0, n) cin >> a[i];
#define show(a, n) rep(i, 0, n) cout << a[i] << " ";
#define modulus 1000000007
#define MAX 100005
#define INF 1000000001
// #define cinv vl a(n) rep(i,0,n) { cin>>a[i]; }
#define fastio()                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
ll dp[MAX];

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


Error: 0

Fixed submission:

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

typedef long long int ll;
typedef long unsigned lu;
typedef vector<ll> v;
typedef pair<ll, ll> p;
typedef vector<p> vp;
#define rep(i, j, k) for (ll i = j; i < k; i++)
#define repr(i, j, k) for (ll i = k; i >= j; i--)
#define read(a, n) rep(i, 0, n) cin >> a[i];
#define show(a, n) rep(i, 0, n) cout << a[i] << " ";
#define modulus 1000000007
#define MAX 100005
#define INF 1000000001
// #define cinv vl a(n) rep(i,0,n) { cin>>a[i]; }
#define fastio()                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
ll a[MAX] = {0};
ll dp[MAX];

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

// void mod(ll l)
// {
//     if(l>=0)
//     {
//         cout<<l%modulus<<"\\n";
//     }
//     else
//     {
//         while(l<0)
//         {
//             l+=modulus;
//         }
//         cout<<l<<"\\n";
//     }

// }

// ll power(ll a, ll b)
// {
//     for (ll i = 1; i <= b; i++)
//     {
//         a*=a;
//     }

//     return a;
// }

// ll sumdigit(ll a)
// {
//     ll sum=0;
//     while(a)
//     {
//         a=sum%10;
//         a=a/10;
//     }
// }