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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

  vec<ll> A(M);
  rep(i, M) cin >> A[i];
  ll ans = N;
  rep(i, M) {
    ans -= A[i];
    if (ans < 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
  int N, M;
  cin >> N >> M;
  vec<int> A(M);
  rep(i, M) cin >> A[i];
  int ans = N;
  rep(i, N) { ans -= A[i]; }
  if (ans < 0)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
  int N;
  int M;
  int kei = 0;

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

  for (int i = 0; i < M; i++) {
    cin >> homework.at(i);
    kei += homework.at(i);
  }
  if (N >= kei) {
    cout << N - kei << endl;
  } else {
    cout << "-1" << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <deque>         // deque
#include <iostream>      // cout, endl, cin
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
  int N;
  int M;
  vector<int> homework(M);
  int kei = 0;

  cin >> N;
  cin >> M;

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

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

int main() {
  int l, i(0), N, M, all;
  cin >> N >> M;
  int *num = new int[M];
  all = 0;
  while (cin >> l) {
    num[i] = l;
    i++;
    if (i == M)
      break;
  }
  for (int i = 0; i < M; i++) {
    all += num[i];
  }
  if (all > N) {
    cout << -1;
  } else {
    cout << N - all;
  }
}

Error: WA

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int c = N;
  vector<int> vec(10010, 0);
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
    c -= vec.at(i);
  }
  if (c >= 0) {
    cout << c << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int c = N;
  vector<int> vec(1000, 0);
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
    if (N >= vec.at(i)) {
      c -= vec.at(i);
    } else {
      break;
    }
  }
  if (c >= 0) {
    cout << c;
  } else {
    cout << -1;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)

int main() {
  ll N, M;
  cin >> N >> M;
  vel A(M);
  rep(i, M) { cin >> A.at(i); }
  ll count = 0;
  rep(i, M) { count += A.at(i); }
  if (count > N) {
    cout << -1 << endl;
  } else {
    cout << N - count << endl;
  }
}

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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)

int main() {
  ll N, M;
  vel A(M);
  cin >> N >> M;
  rep(i, M) { cin >> A.at(i); }
  ll count = 0;
  rep(i, M) { count += A.at(i); }
  if (count > N) {
    cout << -1 << endl;
  } else {
    cout << N - count << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
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);

  if (sum > n) {
    cout << "-1" << endl;
  } else {
    cout << n - sum << 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 <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#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);
  int sum = 0;
  for (int i = 0; i < m; i++) {
    sum += a.at(i);

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

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

int main() {
  ll n, m, t, sum = 0;
  cin >> n >> m;
  ll arr[m];
  for (ll i = 0; i < m; i++)
    cin >> arr[i];
  for (ll i = 0; i < m; i++)
    sum += arr[i];
  t = n - sum;
  if (t < 0)
    cout << "-1";
  else
    cout << t;
  return 0;
}

Error: -11

Fixed submission:

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

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

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

int main() {
  long long m, n;
  cin >> m >> n;
  vector<int> a(n);
  long long sum = 0;

  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  long long ans = m - sum;

  if (ans >= 0) {
    cout << ans << endl;
  } else
    cout << "-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>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int m, n;
  cin >> m >> n;
  vector<int> a;
  int sum = 0;

  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  int ans = m - sum;

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

#include <iostream>
using namespace std;

int n, m;
int a[10000];

int main() {
  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 << endl;
  else
    cout << -1 << endl;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int sum = 0;
int a[200001];
int n;

int main() {
  cin >> n;

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

  int tmp = 1, sum = 0;

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

  for (int i = tmp; i <= n; i++) {
    cout << 0 << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int a[10005];

int main(void) {
  int n, m, sum = 0;
  cin >> n >> m;
  rep(i, 0, m) scanf("%d", &a[i]);
  rep(i, 0, m) sum += a[i];

  ans = n - sum;
  printf("%d\\n", ans >= 0 ? ans : -1);

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int a[10005];

int main(void) {
  int n, m, sum = 0;
  cin >> n >> m;
  rep(i, 0, m) scanf("%d", &a[i]);
  rep(i, 0, n) sum += a[i];

  ans = n - sum;
  printf("%d\\n", ans >= 0 ? ans : -1);

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

#include <iostream>
using namespace std;
int main() {
  int N, M;
  int A = 0;
  int day[10000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> day[i];
    A += day[i];
  };

  if ((N - A) >= 0) {
    cout << N - A << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N, M;
  int A = 0;
  int day[1000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> day[i];
    A += day[i];
  };

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

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

int A[10000];
int main() {
  int N, M;
  cin >> N >> M;

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

  //   int day = N;
  //   for (int i=0; i < M; ++i) {
  //       day -= A[i];
  //       if (day <= 0) {
  //           day = -1;
  //           break;
  //       }
  //   }
  int sum = 0;
  for (int i = 0; i < M; ++i) {
    sum += A[i];
  }
  if (sum <= N)
    cout << (N - sum) << endl;
  else
    cout << -1 << endl;
}

Error: 0

Fixed submission:

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

int A[1010];
int main() {
  int N, M;
  cin >> N >> M;

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

  int day = N;
  for (int i = 0; i < M; i++) {
    day -= A[i];
    if (day <= 0) {
      day = -1;
      break;
    }
  }
  cout << day << endl;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int N, M, res, sum = 0;
  int L[10000000];
  int i = 0;
  cin >> N >> M;

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

  res = N - sum;
  if (res > 0) {
    cout << res << endl;
  } else if (res == 0) {
    cout << "0" << endl;
  } else if (res < 0) {
    cout << "-1" << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int N, M, res, sum = 0;
  int L[100];
  int i = 0;
  cin >> N >> M;

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

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

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

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

  int sum = 0;
  for (int i = 0; i < M; i++) {
    sum += vec[i];
  }

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

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

  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += vec[i];
  }

  if (sum <= N) {
    cout << N - sum << endl;
  } else {
    cout << "-1" << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, M;
  int ans = 0;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < M; i++) {
    ans -= A[i];
  }
  if (N + ans >= 0) {
    cout << N + ans << endl;
  } else {
    cout << -1 << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int i = 0;
  while (i < M) {
    int A;
    cin >> A;
    cout << N - A << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long N;
  long long M;

  cin >> N >> M;

  long long A[M];

  for (long long j = 0; j < M; j++) {

    cin >> A[j];
  }

  long long sum = 0;

  for (long long i = 0; i < M; i++) {

    sum = sum + A[i];
  }

  if (N - sum >= 0) {

    cout << N - sum << endl;

  } else {

    cout << -1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long N;
  long long M;
  long long A[1000];

  cin >> N >> M;

  for (long long j = 0; j < M; j++) {

    cin >> A[j];
  }

  long long sum = 0;

  for (long long i = 0; i < M; i++) {

    sum = sum + A[i];
  }

  if (N - sum >= 0) {

    cout << N - sum << endl;

  } else {

    cout << -1 << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) (int i = 0; i < (n); i++)
#define FOR(i, a, b) (int i = (a); i < (b); i++)
#define INF 100000000000
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m, j;
  cin >> n >> m;
  vector<int> a{n};
  for (int i = 0; i < m; i++) {
    cin >> j;
    n -= j;
  }

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

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) (int i = 0; i < (n); i++)
#define FOR(i, a, b) (int i = (a); i < (b); i++)
#define INF 100000000000
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }

  if (sum > n) {
    cout << -1 << endl;
    return 0;
  }

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

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

int main() {
  int N, M;

  cin >> N >> M;

  int A[N];

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

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

  if (answer < 0)
    cout << -1 << endl;
  else
    cout << answer << endl;

  return 0;
}


Error: 0

Fixed submission:

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

long int N, M;
const long int MAX_M = 10 ^ 4;
long int A[MAX_M];

int main() {

  cin >> N >> M;

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

  long int sum = 0;
  for (long int i = 0; i < M; i++) {
    sum += A[i];
  }
  long int answer = N - sum;

  if (answer < 0)
    cout << -1 << endl;
  else
    cout << answer << endl;

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

#include <iostream>
using namespace std;

int main(void) {
  int N, M;
  int A[10000];
  cin >> N >> M;

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int N, M;
  int A[1000];
  cin >> N >> M;

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

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

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

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

int main() {
  long long d, n;
  cin >> d >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    d -= temp;
  }
  if (d < 0)
    cout << -1 << "\\n";
  else
    cout << d << "\\n";
}


Error: 30

Fixed submission:

// #pragma comment(linker, "/stack: 200000000)
#pragma GCC optimize("03")
// #pragma GCC target("avx2")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse, sse2, sse3, ssse3, sse4, popcnt, abm, mmx, avx,
// tune=native") #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define ar array
#define all(x) (x).begin(), (x).end()
#define inf int(1e9)
#define IOS ios_base::sync_with_stdio(false), cin.tie(0)

using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vii = vector<pii>;

int32_t main() {
  IOS;
  int d, n;
  int sum = 0;
  cin >> d >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
  }
  return d - sum;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ios::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(1000100, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  long long s = accumulate(a.begin() + 1, a.begin() + n + 1, 0);
  if (n - s >= 0)
    cout << n - s << "\\n";
  else
    cout << -1 << "\\n";
}

Error: 0

Fixed submission:

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

int main() {
  ios::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(1000100, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  int s = accumulate(a.begin() + 1, a.end() + n + 1, 0);
  if (n - s >= 0)
    cout << n - s << "\\n";
  else
    cout << -1 << "\\n";
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int day, hw, req[10000] = {};
  cin >> day >> hw;
  for (int i = 0; i < hw; ++i) {
    cin >> req[i];
    day -= req[i];
  }
  if (day >= 0) {
    cout << day;
  } else {
    cout << "-1";
  }
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int day, hw, req[1000] = {};
  cin >> day >> hw;
  for (int i = 0; i < hw; ++i) {
    cin >> req[i];
    day -= req[i];
  }
  if (day >= 0) {
    cout << day;
  } else {
    cout << "-1";
  }
  cout << endl;
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

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

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

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

Error: WA

Fixed submission:

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {

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

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ass = 0, t;
  while (m--) {
    cin >> t;
    ass += t;
  }
  if (ass > n) {
    cout << -1;
  } else
    cout << n - ass;
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long int c[100000000];
  long long int a, b, i, x = 0;
  scanf("%lu%lu", &a, &b);
  for (i = 0; i < b; i++) {
    cin >> 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() {
  unsigned long long N;
  int M;
  cin >> N >> M;
  long long A;
  unsigned long long sum = 0;
  for (int i = 0; i < M; ++i) {
    cin >> A;
    sum += A;
  }
  if (N < sum) {
    cout << "-1";
  } else {
    cout << N - sum;
  }
}

Error: -11

Fixed submission:


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

int main() {
  unsigned long long N;
  int M;
  cin >> N >> M;
  vector<unsigned long long> A;
  unsigned long long sum = 0;
  for (int i = 0; i < M; ++i) {
    cin >> A[i];
    sum += A[i];
  }
  if (N - sum > 0) {
    cout << N - sum;
  } else {
    cout << "-1";
  }
}