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

#include <iostream>
using namespace std;

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

  int A[M];
  long long assigndays = 0;

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

  if (assigndays <= N)
    cout << N - assigndays;

  else
    cout << -1;
}


Error: WA

Fixed submission:


#include <iostream>

using namespace std;

int main() {
  long N;
  int M;
  int A[M];
  long assigndays = 0;

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

  if (M >= N) {
    cout << -1;
  }

  if (M < N) {
    for (int i = 0; i < M; i++) {
      assigndays += A[i];
    }
  }

  if (assigndays < N) {
    cout << N - assigndays;
  } else {
    cout << -1;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m, sum = 0;
  int arr[100000];

  cin >> n >> m;

  for (int j = 0; j < m; j++) {
    cin >> arr[j];
    sum += arr[j];
  }

  n = n - sum;

  if (n < 0)
    cout << -1 << endl;

  else
    cout << n << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n, m;
  int arr[100000];

  cin >> n >> m;

  for (int j = 0; j < m; j++) {
    cin >> arr[j];
  }

  int i = 0;
  while (m--) {
    n = n - arr[n - 1 - i];
    n = n - arr[i];
    i++;
  }

  if (n < 0)
    cout << -1 << endl;

  else
    cout << n << endl;

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

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

typedef long long int ll;

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"

int main() {
  fast;
  ll n, m, i, a[10000], sum = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[i];
  }

  if (sum <= n)
    cout << abs(sum - n) << endl;
  else
    cout << "-1" << endl;

  return 0;
}


Error: 0

Fixed submission:

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

typedef long long int ll;

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define endl "\\n"

int main() {
  fast;
  ll n, m, i, a[10000], sum = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  if (sum <= n)
    cout << abs(sum - n) << endl;
  else
    cout << "-1" << endl;

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

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

#define ll long long
#define ar array

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


Error: WA

Fixed submission:

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

#define ll long long
#define ar array

int main() {
  int n, m, a[1000];
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum <= n) {
    cout << n - sum;
  } else {
    cout << -1;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  ll count = 0;
  rep(i, m) {
    ll a;
    cin >> a;
    count += a;
    if (count > n) {
      cout << -1 << endl;
      break;
    }
  }

  if (count <= n) {
    cout << n - count << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  int a[10100];
  rep(i, n) cin >> a[i];
  int count = 0;
  rep(i, n) count += a[i];

  cout << n - count << endl;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;

  int T = 0;

  cin >> N >> M;
  vector<int> A(M);

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

  if (N < T) {
    cout << "-1" << endl;
  } else {
    cout << N - T << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  vector<int> A(M);
  int T = 0;

  cin >> N >> M;

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

  if (N < T) {
    cout << "-1" << endl;
  } else {
    cout << N - T << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FasterIO                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
int main() {
  FasterIO int cl, a, n[9999], sum = 0, ans;
  cin >> cl >> a;
  for (int i = 0; i < a; i++) {
    cin >> n[i];
    sum = sum + n[i];
  }
  ans = cl - sum;
  if (ans >= 0)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using ll = long long;
using namespace std;
int main() {
  ll cl, a, n[9999], sum = 0, ans;
  cin >> cl >> a;
  for (int i = 0; i < a; i++) {
    cin >> n[i];
    sum = sum + n[i];
  }
  ans = cl - sum;
  if (ans >= 0)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int d, t, a, i, s = 0, r;
  cin >> d >> t;
  for (i = 0; i < t; i++) {
    cin >> a;
    s += a;
  }
  r = d - s;
  if (r < 0)
    cout << "-1" << endl;
  else
    cout << r << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int d, t, a[1000], i, s = 0, r;
  cin >> d >> t;
  for (i = 0; i < t; i++) {
    cin >> a[i];
    s += a[i];
  }
  r = d - s;
  if (r < 0)
    cout << "-1" << endl;
  else
    cout << r << endl;
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, m, a, count = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a;
    count += a;
  }
  if (n - count < 0) {
    cout << "-1" << endl;
  } else {
    cout << n - count << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m, kadaiSum = 0;
  int a[1000];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    kadaiSum += a[i];
  }
  n = n - kadaiSum;
  if (n < 0) {
    cout << -1 << endl;
  } else {
    cout << n << endl;
  }
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll A[10000];

int main() {
  ll N, M;
  cin >> N >> M;

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

  ll ans = N;

  for (int i = 0; i < M; i++) {
    ans -= A[i];
  }

  if (ans < -1)
    ans = -1;

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:


//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll A[1000];

int main() {
  ll N, M;
  cin >> N >> M;

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

  ll ans = N;

  for (int i = 0; i < M; i++) {
    ans -= A[i];
  }

  if (ans < -1)
    ans = -1;

  cout << ans << endl;

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> V(M);
  for (int i = 0; i < M; i++) {
    cin >> V.at(i);
  }
  int P = 0;
  for (int i = 0; i < M; i++) {
    P += V.at(i);
  }
  if (N - P >= 0)
    cout << N - P;
  else
    cout << "-1";
}

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, M;
  cin >> N >> M;
  vector<int> V;
  for (int i = 0; i < M; i++) {
    cin >> V.at(i);
  }
  int P = 0;
  for (int i = 0; i < M; i++) {
    P += V.at(i);
  }
  if (N - P >= 0)
    cout << N - P;
  else
    cout << "-1";
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int N, M;

  cin >> N;
  cin >> M;

  int A[M];
  int T = 0;

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

  if (N >= T) {
    cout << N - T << endl;
  } else {
    cout << -1 << endl;
  }
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N, M;

  cin >> N;
  cin >> M;

  int A[M];
  int T = 0;

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

  if (N >= T) {
    cout << N - T << endl;
  } else {
    cout << -1 << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  long n, m, i, left;
  long total = 0;
  cin >> n >> m;

  long a[m];
  for (i = 0; i < m; i++) {
    scanf("%ld", &a[i]);
    total = total + a[i];
  }

  left = n - total;

  if (total > n) {
    printf("-1\\n");
  } else {
    printf("%ld\\n", left);
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  long n, m, i;
  long total = 0;
  cin >> n >> m;

  long a[i];
  for (i = 0; i < m; i++) {
    scanf("%ld", &a[i]);
    int total = total + a[i];
  }

  if (total > n) {
    printf("-1\\n");
  } else {
    printf("%ld\\n", n - total);
  }

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

#include <bits/stdc++.h>
#define FRU freopen("out.txt", "w", stdout);
#define FRO freopen("in.txt", "r", stdin);
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define mp make_pair
#define ff first
#define ss second
#define flash                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define mem(ara, n) memset(ara, n, sizeof ara)
#define fr(i, j, n) for (i = j; i < n; i++)
#define rf(i, j, n) for (i = n; i >= j; i--)
#define inf 2147483647
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vch vector<char>
#define itr ::iterator
#define msi map<string, int>
#define psi pair<string, int>
#define vii vector<pair<int, int>>
#define all(n) n.begin(), n.end()
#define INF 10000000000000000LL
#define pi 3.1415926535897932384626434
#define sii set<int>
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mid3(a, b, c) min(max(a, b), max(b, c), max(a, b))
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define endl '\\n'
#define endll cout << "\\n";
#define spc ' '
#define ld long double

using namespace std;

int main() {
  flash string s, st;
  int n, t, T, i, j, J, I, k, m;
  char ch;
  cin >> n;
  cin >> m;
  fr(i, 0, m) {
    cin >> k;
    n -= k;
  }
  if (n < 0)
    n = -1;
  cout << n;
  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  int i, n, m, a[10000] = {};
  int s = 0;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  if (n - s >= 0) {
    printf("%d\\n", n - s);
  } else {
    printf("-1\\n");
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int lim, num, sum;
  vector<int> v1;
  while (cin >> num >> lim) {
    sum = 0;
    for (int i = 0; i < lim; i++) {
      int temp;
      cin >> temp;
      v1.push_back(temp);
      sum += v1[i];
    }
    if (num >= sum) {
      cout << (num - sum) << endl;
    } else {
      cout << "-1" << endl;
    }
    break;
  }
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long int c[1000];
  long long int a, b, i, x = 0;
  scanf("%lld%lld", &a, &b);
  for (i = 0; i < b; i++) {
    scanf("%lld", &c[i]);
  }
  for (i = 0; i < b; i++) {
    x = x + c[i];
  }

  if ((a - x) > 0)
    cout << a - x << endl;
  else
    cout << "-1" << endl;
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i);
  }
  int sum = 0;
  for (int i = 0; i < M; i++) {
    sum += A.at(i);
  }
  cout << max(N - sum, -1) << 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, M;
  cin >> N >> M;
  vector<int> A;
  for (int i = 0; i < M; i++) {
    cin >> A.at(i);
  }
  int sum = 0;
  for (int i = 0; i < M; i++) {
    sum += A.at(i);
  }
  cout << max(N - sum, -1) << endl;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

long long A[1111111];
int main() {
  long long N, M;
  cin >> N >> M;
  long long total = 0;
  rep(i, M) {
    cin >> A[i];
    total += A[i];
  }

  if (total > N)
    cout << "-1" << endl;
  else
    cout << N - total << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int A[1111];
int main() {
  int N, M;
  cin >> N >> M;
  int total = 0;
  rep(i, M) {
    cin >> A[i];
    total += A[i];
  }

  if (total > N)
    cout << "-1" << endl;
  else
    cout << N - total << endl;

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

#include <iostream>

using namespace std;
int Solve(int a, int b) {
  int Array[10000];
  int sum = 0;
  int ans;
  for (int i = 0; i < b; i++) {
    cin >> Array[i];
    sum += Array[i];
  }
  ans = a - sum;
  if (ans < 0) {
    return -1;
  } else
    return ans;
}
int main() {
  int x, y;
  cin >> x >> y;
  cout << Solve(x, y);
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;
int Solve(int a, int b) {
  int Array[1000];
  int sum = 0;
  int ans;
  for (int i = 0; i < b; i++) {
    cin >> Array[i];
  }
  for (int i = 0; i < b; i++) {
    sum += Array[i];
  }
  ans = a - sum;
  if (ans < 0) {
    return -1;
  } else
    return ans;
}
int main() {
  int x, y;
  cin >> x >> y;
  cout << Solve(x, y);
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

Error: WA

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int ara[10000];

  for (int i = 1; i <= m; i++) {
    cin >> ara[i];
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    sum = sum + ara[i];
  }
  if (n >= sum)
    cout << n - sum << endl;
  else
    cout << "-1" << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int ara[1000];

  for (int i = 1; i <= m; i++) {
    cin >> ara[i];
  }
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    sum = sum + ara[i];
  }
  if (n >= sum)
    cout << n - sum << endl;
  else
    cout << "-1" << endl;

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

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int n, m, a[10001];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    n = n - a[i];
  }

  if (n < 0) {
    cout << -1 << endl;
  } else {
    cout << n << endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int n, m, a[1001];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    n = n - a[i];
  }

  if (n < 0) {
    cout << -1 << endl;
  } else {
    cout << n << endl;
  }
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, x, s = 0, t, i;
  cin >> a >> t;
  for (i = 0; i < t; i++) {
    cin >> x;
    s += x;
  }
  if ((a - s) < 0)
    cout << "-1" << endl;
  else
    cout << a - s << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, x[1000], s = 0, t, i;
  cin >> a >> t;
  for (i = 0; i < t; i++) {
    cin >> x[i];
    s += x[i];
  }
  if ((a - s) < 0)
    cout << "-1" << endl;
  else
    cout << a - s << endl;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  int total = 0;
  cin >> N >> M;
  vector<int> data(M);
  for (int i = 0; i < M; i++) {
    cin >> data.at(i);
    total += data.at(i);
  }
  if ((N - total) < 0) {
    cout << -1 << endl;
  } else {
    cout << N - total << endl;
  }
}


Error: 0

Fixed submission:

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

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

#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {

  int64_t n, m;

  cin >> n >> m;

  int64_t s = 0;
  for (int64_t i = 0; i < m; i++) {
    int a = 0;
    cin >> a;
    s += a;
  }

  if (n >= s) {
    cout << n - s << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

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 <algorithm>
#include <bitset>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {

  int n, m;

  cin >> n >> m;
  vector<int> a;

  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
  }
  int64_t s = 0;

  for (int i = 0; i < m; i++) {
    s += a.at(i);
  }

  if (n >= s) {
    cout << n - s << endl;
  } else {
    cout << -1 << endl;
  }

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

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

int main() {
  int M, N, l, i = 0, a[10000], j = 0;
  cin >> M >> N;
  while (cin >> l) {
    a[i] = l;
    i++;
  }
  while (j < N) {
    M = M - a[j];
    j++;
  }
  if (M >= 0) {
    cout << M;
  } else {
    cout << -1;
  }
}

Error: WA

Fixed submission:

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

int main() {
  int M, N, l, i = 0, a[1000], j = 0;
  cin >> M >> N;
  while (cin >> l) {
    a[i] = l;
    i++;
  }
  while (j < N) {
    M = M - a[j];
    j++;
  }
  if (M >= 0) {
    cout << M;
  } else {
    cout << -1;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int a[100000];
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    ans += a[i];
  }
  if (ans > n) {
    cout << -1;
  } else {
    cout << n - ans;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int a[1000];
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    ans += a[i];
  }
  if (ans > n) {
    cout << -1;
  } else {
    cout << n - ans;
  }
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int vacationDayCount, homeworkCount;
  cin >> vacationDayCount >> homeworkCount;

  vector<int> spends(homeworkCount);
  for (auto index = 0; index < homeworkCount; ++index) {
    cin >> spends.at(index);
  }

  const auto playableDayCount =
      vacationDayCount - accumulate(spends.begin(), spends.end(), 0);

  cout << ((playableDayCount >= 0) ? playableDayCount : -1);

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int vacationDayCount, homeworkCount;
  vector<int> spends(homeworkCount);

  cin >> vacationDayCount >> homeworkCount;
  for (auto index = 0; index < homeworkCount; ++index) {
    cin >> spends.at(index);
  }

  const auto playableDayCount =
      vacationDayCount - accumulate(spends.begin(), spends.end(), 0);

  cout << (playableDayCount >= 0) ? playableDayCount : -1;

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

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

Error: WA

Fixed submission:

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