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

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


Error: 0

Fixed submission:

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

#include <algorithm>
#include <bits/stdc++.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define ll long long
#define endl "\\n"
#define pb push_back
#define mp make_pair

int solve() {
  ll n, k, total = 0, num;
  cin >> n >> k;

  for (ll i = 0; i < k; i++) {
    cin >> num;
    total += num;
  }

  if (total > n)
    cout << -1;
  else
    cout << n - total;

  return 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  /*ll t;
  cin>>t;
  while(t--)*/
  solve();

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define ll long long
#define endl "\\n"
#define pb push_back
#define mp make_pair

int solve() {
  ll n, k;
  cin >> n >> k;

  vector<ll> nums(0, k);

  for (ll i = 0; i < k; i++) {
    cin >> nums[i];
  }

  ll total = accumulate(nums.begin(), nums.end(), 0);

  if (total > n)
    cout << -1;
  else
    cout << n - total;

  return 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  /*ll t;
  cin>>t;
  while(t--)*/
  solve();

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

#include <iostream>

using namespace std;

int main() {
  int n;
  int m;
  int a[10000];

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

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  int m;
  int a[1000];

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

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

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

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

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


Error: 0

Fixed submission:

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

#include <iostream>

using namespace std;

int main() {
  int N;
  int M;
  int A;
  int b;
  cin >> N >> M;
  while (M > 0) {
    cin >> A;
    b = b + A;
    M--;
  }
  if (N - b >= 0)
    cout << N - b;
  else
    cout << "-1";
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

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


Error: -11

Fixed submission:

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

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

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

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

  if (sum > n)
    cout << -1;
  else
    cout << n - sum;

  return 0;
}

Error: WA

Fixed submission:

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

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

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

  if (sum > n)
    cout << -1;
  else
    cout << n - sum;

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

  for (int i = 0; i < M; i++) {
    N -= a.at(i);
  }

  if (N < 0)
    N = -1;

  cout << N << endl;
  return 0;
}

Error: 0

Fixed submission:

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

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

  vector<int> a(10000);
  for (int i = 1; i <= M; i++) {
    cin >> a.at(i);
  }

  int sum = 0;
  for (int i = 1; i <= M; i++) {
    sum += a.at(i);
  }

  if (N < sum)
    cout << "-1" << endl;

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

// C++ program to add two binary strings
#include <bits/stdc++.h>
using namespace std;

// Driver program
int main() {
  int N, M, sum = 0, ans;
  cin >> N >> M;
  int arr[M];

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

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

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

  return 0;
}


Error: WA

Fixed submission:

// C++ program to add two binary strings
#include <bits/stdc++.h>
using namespace std;

// Driver program
int main() {
  int N, M, sum = 0, ans;
  int arr[M];
  cin >> N >> M;

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

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

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

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

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

int main() {
  int N, M; // N日、M個の宿題
  int sum = 0;

  cin >> N >> M;

  int A[M];

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

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

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

Error: -11

Fixed submission:

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

int main() {
  int N, M; // N日、M個の宿題
  int A[M];
  int sum = 0;

  cin >> N >> M;

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

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

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

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

int main() {
  int n, m;
  int a[100100];
  int s = 0;

  cin >> n >> m;

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

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  int a[100];
  int s = 0;

  cin >> n >> m;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(m);
  rep(i, m) cin >> A.at(i);

  int sum = accumulate(A.begin(), A.end(), 0);
  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 2) >= this->size() (which is 2)


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(m);
  rep(i, n) cin >> A.at(i);

  int sum = accumulate(A.begin(), A.end(), 0);
  if (sum > n) {
    cout << -1 << endl;
  } else {
    cout << n - sum << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, input;
  int sum = 0;
  vector<int> A;
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    cin >> input;
    A.push_back(input);
  }
  sum = accumulate(A.begin(), A.end(), 0);
  if (sum > N) {
    cout << -1;
  } else {
    cout << (N - sum);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, input;
  int sum = 0;
  vector<int> A;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> input;
    A.push_back(input);
  }
  for (int j = 0; j < N; j++) {
    sum += A[j];
  }
  if (sum > N) {
    cout << -1;
  } else {
    cout << (N - sum);
  }
  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> vec(M);
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
  }
  int a = 0;
  for (int i = 0; i < M; i++) {
    a += vec.at(i);
  }
  if (N < a) {
    cout << "-1" << endl;
  } else {
    cout << N - a << endl;
  }
}


Error: 0

Fixed submission:

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

#include <iostream>
using namespace std;

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

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n, k, b, d[100], a[100], m[100];
  int count = 0;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> d[i];
    for (int j = 0; j < d[i]; j++) {
      cin >> a[j];
      for (b = 0; b < j; b++) {
        if (a[j] == m[b]) {
          m[b] = 0;
          break;
        }
      }
      if (b == j) {
        a[j] = m[b];
      }
    }
  }
  for (int l = 0; l < n; l++) {
    if (m[l] > 0)
      count++;
  }
  cout << n - count << endl;
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

Error: WA

Fixed submission:

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

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void solving() {
  int n, m;
  cin >> n >> m;
  int a[m];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  n = n - sum;
  if (n < 0)
    cout << "-1";
  else
    cout << n << "\\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solving();
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define PI 3.141592653589793238

typedef long long ll;

using namespace std;

int main() {

  ll n, m, sum = 0;

  cin >> n >> m;

  ll a[m];

  for (ll i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[i];
  }

  if (sum > n)
    cout << -1 << endl;
  else
    cout << abs(n - sum) << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define PI 3.141592653589793238

typedef long long ll;

using namespace std;

int main() {

  ll n, m, sum = 0;

  cin >> n >> m;

  ll a[m];

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

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

const int N = 200005;
const long double EPS = 1e-9;
const long double PI = acos(-1.);

int main() {
  //    #ifdef LOCAL
  //    freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  //    #endif

  ll n, m, sum = 0, a[N];
  scanf("%I64d%I64d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
  }
  if (sum > n)
    return printf("%d\\n", -1), 0;
  printf("%I64d\\n", n - sum);

  return 0;
}


Error: WA

Fixed submission:

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

const int N = 200005;
const long double EPS = 1e-9;
const long double PI = acos(-1.);

int main() {
  //    #ifdef LOCAL
  //    freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  //    #endif

  ll n, m, sum = 0, a[N];
  scanf("%I64d%I64d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
  }
  if (sum > n)
    return printf("%d\\n", -1);
  printf("%I64d\\n", n - sum);

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

#include <bits/stdc++.h>
using namespace std;
int a[10010];

int main() {
  int s = 0;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    s += a[i];
  }
  if (n < s) {
    cout << "-1\\n";
    return 0;
  }
  cout << n - s << "\\n";
  return 0;
}

Error: 0

Fixed submission:

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

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

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

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

Error: WA

Fixed submission:

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

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

#include <iostream>

using namespace std;

int main() {
  int n, m, a[10000], need_days = 0;

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

  int play_days = n - need_days;

  if (play_days < 0) {
    play_days = -1;
  }

  cout << play_days << endl;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m, a[1000], need_days = 0;

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

  int play_days = n - need_days;

  if (play_days < 0) {
    play_days = -1;
  }

  cout << play_days << endl;

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

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

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

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


Fixed submission:

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

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

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

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

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

  // your code goes here
  return 0;
}

Error: 30

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  int sum = 0;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    a[i] = x;
    sum += a[i];
  }
  int k = n - sum;
  if (k < 0) {
    return -1;
  }
  return k;

  // your code goes here
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

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


Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, m, arr[30], sum = 0, result;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < m; i++) {
    sum = sum + arr[i];
    result = n - sum;
    if (result > 0)
      cout << result << endl;
    else if (result == 0)
      cout << "0" << 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;
  int sum = 0;
  vector<int> a(M);
  for (int i = 0; i < M; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  if (sum <= N) {
    cout << N - sum << 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 2) >= this->size() (which is 2)


Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int sum = 0;
  vector<int> a(M);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }

  if (sum <= N) {
    cout << N - sum << endl;
  } else {
    cout << -1 << endl;
  }
  // ここにプログラムを追記
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long int a, b, i, x = 0, c;
  cin >> a >> b;
  while (b--) {
    cin >> c;
    x = x + c;
  }
  if ((a - x) < 0)
    cout << "-1" << endl;
  else
    printf("%d\\n", a - x);
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long int c[1000];
  long int a, b, i, x = 0;
  cin >> 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;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
int main() {
  fast;
  int a[100001];
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    sum += a[i];
  }
  if (sum > n) {
    cout << -1 << endl;
  } else
    cout << n - sum << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }
int main() {
  fast;
  int a[10001];
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  if (sum > n) {
    cout << -1 << endl;
  } else
    cout << n - sum << endl;

  return 0;
}