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

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];

  int sum = 0;
  rep(i, m) sum += a[i];
  int res = n - sum;
  if (res < 0)
    res = -1;
  cout << res << "\\n";
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) cin >> a[i];

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

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string m1, m2, w;
  int N;
  getline(cin, m1);
  istringstream ss1(m1);
  ss1 >> w;
  N = stoi(w);
  getline(cin, m2);
  istringstream ss(m2);
  do {
    string word;
    ss >> word;
    if (word != "")
      N -= stoi(word);
  } while (ss);
  if (N < 0) {
    cout << "-1" << endl;
  } else {
    cout << N << endl;
  }
}

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


Fixed submission:

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string m1, m2, w;
  int N;
  getline(cin, m1);
  istringstream ss1(m1);
  ss1 >> w;
  N = stoi(w);
  getline(cin, m2);
  istringstream ss(m2);
  do {
    string word;
    ss >> word;
    N -= stoi(word);
  } while (ss);
  if (N < 0) {
    cout << "-1" << endl;
  } else {
    cout << N << endl;
  }
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  int *a = new int[m];

  int s = 0;

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

  return 0;
}


Error: WA

Fixed submission:

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

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

#include <bits/stdc++.h>

using namespace std;

void func_to_create() {
  unsigned int N, M;
  cin >> N >> M;
  unsigned int sum = 0;
  for (unsigned int i = 0; i < M; i++) {
    unsigned int a;
    cin >> a;
    sum += a;
  }

  if (sum > N) {
    cout << -1 << endl;
  } else {
    cout << N - sum << endl;
  }
}
int main() {
  // making data IO Fast
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  /****************************/

  func_to_create();

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

bool func_to_create() {
  unsigned int N, M;
  cin >> N >> M;
  unsigned int sum = 0;
  for (int i = 0; i < M; i++) {
    unsigned int a;
    cin >> a;
    sum += a;
  }

  if (sum > N) {
    cout << -1 << endl;
  } else {
    cout << N - sum << endl;
  }
}
int main() {
  // making data IO Fast
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  /****************************/

  func_to_create();

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

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


Error: WA

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define N 100010
#define M 200010
#define A 110
#define endl "\\n"
#define mod 1000000007

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n, m;
  int arr[10010];
  ll tot = 0;

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define N 100010
#define M 200010
#define A 110
#define endl "\\n"
#define mod 1000000007

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n, m;
  int arr[1010];
  ll tot = 0;

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

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

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

#include <bits/stdc++.h>

using namespace std;

int A[10005];

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  long long n, m;
  cin >> n >> m;
  long long total = 0;
  for (int i = 0; i < m; ++i) {
    cin >> A[i];
    total += A[i];
  }
  total = n - total;
  if (total >= 0)
    cout << total << '\\n';
  else
    cout << -1 << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int A[10005];

int main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  long long n, m;
  cin >> n >> m;
  long long total = 0;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    total += A[i];
  }
  total = n - total;
  if (total >= 0)
    cout << total << '\\n';
  else
    cout << -1 << '\\n';
  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 REPV(iter, v)                                                          \\
  for (auto(iter) = (v).begin(); (iter) != (v).end(); ++(iter))
#define ALL(v) (v).begin(), (v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M);
  REP(i, M) cin >> A[i];
  ll sum = 0;
  REP(i, M) sum += A[i];
  ll ans;
  if (sum <= N)
    ans = N - sum;
  else
    ans = -1;

  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPV(iter, v)                                                          \\
  for (auto(iter) = (v).begin(); (iter) != (v).end(); ++(iter))
#define ALL(v) (v).begin(), (v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M);
  REP(i, M) cin >> A[i];
  ll sum = 0;
  REP(i, N) sum += A[i];
  ll ans;
  if (sum <= N)
    ans = N - sum;
  else
    ans = -1;

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

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> homework(N);
  for (int j = 0; j < M; j++) {
    cin >> homework.at(j);
  }
  for (int i = 0; i < M; i++) {
    N = N - homework.at(i);
  }
  if (N >= 0) {
    cout << N;
  }
  if (N < 0) {
    cout << "-1";
  }
  return 0;
}

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


Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> days(N);
  for (int j = 0; j = N; j++) {
    cin >> days.at(j);
  }
  for (int i = 0; i = N; i++) {
    N = N - days.at(i);
  }
  if (N >= 0) {
    cout << N;
  }
  if (N < 0) {
    cout << "-1";
  }
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
int n, m;

int a[100110];
int main() {
  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;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int n, m;

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

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

#include <iostream>
using namespace std;

int main() {
  int holidays, homeworks;
  int Sum = 0;
  cin >> holidays >> homeworks;
  int NeedTime[homeworks];
  for (int i = 0; i < homeworks; i++) {
    cin >> NeedTime[i];
    Sum += NeedTime[i];
  }

  int PlayTimes = holidays - Sum;

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int holidays, homeworks;
  int NeedTime[homeworks];
  int Sum = 0;
  cin >> holidays >> homeworks;
  for (int i = 0; i < homeworks; i++) {
    cin >> NeedTime[i];
    Sum += NeedTime[i];
  }
  cout << holidays - Sum << endl;

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

#include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop                                                                   \\
  char nyaa;                                                                   \\
  cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define Per(i, sta, n) for (int i = n - 1; i >= sta; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int n, m;
int a[50010];

void solve() {
  cin >> n >> m;
  int S = 0;
  rep(i, m) {
    cin >> a[i];
    S += a[i];
  }
  if (n >= S)
    cout << n - S << endl;
  else
    cout << -1 << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(50);
  solve();
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop                                                                   \\
  char nyaa;                                                                   \\
  cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define Per(i, sta, n) for (int i = n - 1; i >= sta; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int n, m;
int a[5010];

void solve() {
  cin >> n >> m;
  int S = 0;
  rep(i, m) {
    cin >> a[i];
    S += a[i];
  }
  if (n >= S)
    cout << n - S << endl;
  else
    cout << -1 << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(50);
  solve();
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>>
    vec_p; // vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N, M;
  string S;
  cin >> N >> M;

  vector<ll> vec(M);

  for (ll i = 0; i < M; i++) {
    cin >> vec.at(i);
  }
  ll tmp = 0;
  for (ll i = 0; i < M; i++) {
    tmp += vec.at(i);
  }

  if (tmp <= N) {
    cout << N - tmp << 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;

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>>
    vec_p; // vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N, M;
  string S;
  cin >> N >> M;

  vector<ll> vec(M);

  for (ll i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  ll tmp = 0;
  for (ll i = 0; i < N; i++) {
    tmp += vec.at(i);
  }

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

#include <bits/stdc++.h>
#include <stack>
#include <vector>

using namespace std;

int main() {

  long int n, m;
  cin >> n >> m;

  long int a[m];

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

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

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

  return 0;
}

Error: WA

Fixed submission:

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

int main() {

  long int n, m;
  cin >> n >> m;

  long int a[m];

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

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

  if (sum <= m)
    cout << m - sum << endl;
  else if (sum > m)
    cout << "-1" << endl;

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

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

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

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

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

  return (0);
}

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;

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

  for (ll i = 0; i < M; i++) {
    cost += A.at(i);
  }

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

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

#include <iostream>
using namespace std;

#define M_PI 3.14159265358979323846
int main() {
  int N, M, sum = 0;
  int A[10000];
  cin >> N >> M;

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

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

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

#define M_PI 3.14159265358979323846
int main() {
  int N, M, sum = 0;
  int A[100];
  cin >> N >> M;

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

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
/************************************************/
#define rep(i, n) for (int i = 0; i < n; i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i, a, n) for (int i = a; i < n; i++)
#define foreach(i, c)                                                          \\
  for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); i++)
#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(), s.end()
#define zero(x) memset(x, 0, sizeof(x))
#define vii vector<pair<int, int>>
#define mpis map<int, string>
#define mpii map<int, int>
#define mpsi map<string, int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9')
    c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
ll n, m, a[10001];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  ll sum = 0;
  rep(i, m) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum > n)
    cout << -1;
  else
    cout << n - sum;
  re 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
/************************************************/
#define rep(i, n) for (int i = 0; i < n; i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i, a, n) for (int i = a; i < n; i++)
#define foreach(i, c)                                                          \\
  for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); i++)
#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(), s.end()
#define zero(x) memset(x, 0, sizeof(x))
#define vii vector<pair<int, int>>
#define mpis map<int, string>
#define mpii map<int, int>
#define mpsi map<string, int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9')
    c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
int n, m, a[1001];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  int sum = 0;
  rep(i, m) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum > n)
    cout << -1;
  else
    cout << n - sum;
  re 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
int a[10010];

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int a[1010];

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

#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define square(a) (a) * (a)

typedef long long ll;
typedef string str;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  cin >> a >> b;

  int sum = 0;
  loop(i, 0, b) {
    int c;
    cin >> c;
    sum += c;
  }

  if (a >= sum)
    cout << a - sum;
  else
    cout << -1;
}


Error: WA

Fixed submission:

#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define square(a) (a) * (a)

typedef long long ll;
typedef string str;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  cin >> a >> b;

  int c[100];

  int sum = 0;
  loop(i, 0, b) {
    cin >> c[i];
    sum += c[i];
  }

  if (a >= sum)
    cout << a - sum;
  else
    cout << -1;
}
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;
  vector<int> syukudai_nissuu(M);
  for (int i = 0; i < M; i++) {
    cin >> syukudai_nissuu.at(i);
  }
  sum = accumulate(syukudai_nissuu.begin(), syukudai_nissuu.end(), 0);

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


Fixed submission:

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

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

  int sum;
  vector<int> syukudai_nissuu;
  for (int i = 0; i < M; i++) {
    cin >> syukudai_nissuu.at(i);
  }
  sum = accumulate(syukudai_nissuu.begin(), syukudai_nissuu.end(), 0);

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