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

#include <iostream>
using namespace std;
int main() {
  float r;
  cin >> r;
  cout << 3.14 * r * 2;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int area(int radius) {
  float PI = 3.14;
  cout << PI * radius * 2;
}
int main() {
  int r;
  cin >> r;
  cout << area(r);
}
Problem p02705 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, b) for (i = 0; i < b; ++i)
#define repp(i, a, b) for (i = a; i < b; ++i)
#define endl "\\n"
// #define LLONG_MAX 99999999999999
typedef long long int lli;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli t, n, i, j, b, a, q, m;
  double r;
  cin >> r;
  cout << 2.0 * 3.141 * r << 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;
#define rep(i, b) for (i = 0; i < b; ++i)
#define repp(i, a, b) for (i = a; i < b; ++i)
#define endl "\\n"
// #define LLONG_MAX 99999999999999
typedef long long int lli;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli t, n, i, j, b, a, q, m;
  cin >> n >> m;
  vector<lli> v(m);
  rep(i, m) cin >> v[i];
  lli ans = 0;
  rep(i, m) { ans += v[i]; }
  if (ans > n) {
    cout << -1 << endl;
  } else {
    cout << n - ans << endl;
  }
}
Problem p02705 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  double r;
  cin >> r;
  cout << r * 2 * 3.14159265358979323846 << endl;
  return 0;
}

Error: 6

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  double r;
  cin >> r;
  return r * 2 * 3.14;
}
Problem p02705 (C++) — buggy submission, verdict: Runtime Error

/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define gcd(a, b) __gcd(a, b);
int main() {
  fastio;
  double ans, r, p = 3.1416;
  cin >> r;
  ans = p * r * 2;
  cout << ans << endl;
}

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


Fixed submission:

/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define gcd(a, b) __gcd(a, b);
int main() {
  fastio;
  ll n, m, i, s = 0;
  cin >> n >> m;
  vector<ll> v(m);
  for (i = 0; i < m; i++) {
    cin >> v[i];
  }
  for (i = 0; i < m; i++) {
    s = s + v[i];
  }
  if (s > n)
    cout << "-1" << endl;
  else {
    cout << n - s << endl;
  }
}
Problem p02705 (C++) — buggy submission, verdict: Runtime Error

///******* In the name of Allah *******///

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

void Ok() {
  int a;
  double aa, bb;
  scanf("%d", &a);
  aa = a;
  bb = 2 * 3.1416 * aa;
  printf("%0.2lf", bb);
}

int main() {
  Ok();

  return 0;
}


Error: WA

Fixed submission:

///******* In the name of Allah *******///

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

void Ok() {
  int a;
  double aa, bb;
  scanf("%ld", &a);
  aa = a;
  bb = 2 * 3.1416 * aa;
  printf("%0.2lf", bb);
}

int main() {
  Ok();

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

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)
#define all(ct) ct.begin(), ct.end()
#define endl "\\n"
#define fr(i, a) for (auto i : a)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define in(d, v) d.find(v) != d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return modexp((x * x) % md, n / 2, md);
  return (x * modexp((x * x) % md, n / 2, md)) % md;
}

int main() {
  fastio;
  // clock_t tm = clock();
  double r;
  cin >> r;
  double ans = 2 * PI * r;
  cout << setprecision(8) << ans << endl;
  // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<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 int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string> vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)
#define all(ct) ct.begin(), ct.end()
#define endl "\\n"
#define fr(i, a) for (auto i : a)
#define f(i, a, b) for (int i = a; i < b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define in(d, v) d.find(v) != d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return modexp((x * x) % md, n / 2, md);
  return (x * modexp((x * x) % md, n / 2, md)) % md;
}

int main() {
  fastio;
  // clock_t tm = clock();
  ll n, m, s = 0;
  cin >> n >> m;
  vl a(m);
  f(i, 0, m) {
    cin >> a[i];
    s += a[i];
  }
  if (s > n)
    cout << -1 << endl;
  else
    cout << n - s << endl;
  // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}
Problem p02705 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  int r;
  double cir;

  do {
    scanf("%d", &r);
  } while (r < 1 || r > 100);

  cir = 2 * r * 3.14159;

  printf("%f", cir);

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  double r;
  double cir;

  do {
    scanf("%d", &r);
  } while (r < 1 || r > 100);

  cir = 2 * r * 3.14159;

  printf("%d", cir);

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

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

int main() {
  int R;
  cin >> R;
  float ans = R * 2 * 3.14159265358979323846;
  cout << ans << endl;
}

Error: WA

Fixed submission:

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

bool func_to_create() {
  unsigned int R;
  cin >> R;
  float ans = R * 2 * M_PI;
  cout << ans << endl;
}
int main() {
  // making data IO Fast
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  /****************************/

  func_to_create();

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long double a;
  cin >> a;
  cout << 2.0 * a * 3.14159265358979;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union {
  vector<ll> par;
  Union(ll a) { par = vector<ll>(a, -1); }
  ll find(ll a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(ll a, ll b) { return (find(a) == find(b)); }
  ll size(ll a) { return -par[find(a)]; }
  void unite(ll a, ll b) {
    ll c = find(a), d = find(b);
    if (c == d)
      return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};

int main() {
  ll n, m, b = 0;
  cin >> n >> m;
  ll a[m];
  rep(i, m) {
    cin >> a[i];
    b += a[i];
  }
  if (n - b < -1)
    b = n + 1;
  cout << n - b;
}
Problem p02705 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  double pi = acos(-1);
  int n;
  cin >> n;
  double ans = 2 * pi * n;
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  ll n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  ll sum = 0;
  for (int i = 1; i <= m; i++) {
    ll t;
    cin >> t;
    sum += t;
  }
  if (n >= sum)
    cout << n - sum << "\\n";
  else
    cout << -1 << "\\n";
  return 0;
}
Problem p02705 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

double solve(int64_t R) {
  // TODO: edit here
  return (double)R * M_PI * 2;
}

// generated by online-judge-template-generator v4.1.0
// (https://github.com/kmyk/online-judge-template-generator)
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  constexpr char endl = '\\n';
  int64_t R;
  cin >> R;
  auto ans = solve(R);
  cout << ans << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

double solve(int64_t R) {
  // TODO: edit here
  cout << (long double)R * M_PI * 2 << endl;
}

// generated by online-judge-template-generator v4.1.0
// (https://github.com/kmyk/online-judge-template-generator)
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  constexpr char endl = '\\n';
  int64_t R;
  cin >> R;
  auto ans = solve(R);
  cout << ans << endl;
  return 0;
}
Problem p02705 (C++) — buggy submission, verdict: Time Limit Exceeded

// =====================================================================================
//
//       Filename:  at.cpp
//
//    Description:
//
//        Version:  1.0
//        Created:  19/04/20 05:21:38 PM IST
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com
//   Organization:
//
// =====================================================================================

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
// #define _SHOW_TIME

void solve() {
  // your code here;
  int n, m;
  cin >> n;
  double d = 22 / 7.0;
  d *= 2;
  d *= n;
  cout << d << endl;
}
int32_t main() {
  /////////////////////////////////////
#ifdef _SHOW_TIME
  int tt = (int)clock();
#endif
  /////////////////////////////////////
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  /////////////////////////////////////
  solve();
/////////////////////////////////////
#ifdef _SHOW_TIME
  cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl;
#endif
  /////////////////////////////////////
  return 0;
}


Error: TLE

Fixed submission:

// =====================================================================================
//
//       Filename:  at.cpp
//
//    Description:
//
//        Version:  1.0
//        Created:  19/04/20 05:21:38 PM IST
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com
//   Organization:
//
// =====================================================================================

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
// #define _SHOW_TIME

void solve() {
  // your code here;
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    sum += x;
  }

  if (sum <= n)
    cout << n - sum << endl;
  else
    cout << "-1" << endl;
}
int32_t main() {
  /////////////////////////////////////
#ifdef _SHOW_TIME
  int tt = (int)clock();
#endif
  /////////////////////////////////////
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  /////////////////////////////////////
  solve();
/////////////////////////////////////
#ifdef _SHOW_TIME
  cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl;
#endif
  /////////////////////////////////////
  return 0;
}
Problem p02705 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <math.h>
#define PI acos(-1)

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  printf("%lf", 2 * n * PI);
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <cstdio>
#include <math.h>
#define PI acos(-1)

using namespace std;

int main() {
  int n;
  scanf("%lld", &n);
  printf("%lf", 2 * n * PI);
}
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 k;
  k = 0;
  for (int i = 0; i < m; i++) {
    k += v.at(i);
  }
  if (n < k) {
    cout << -1 << endl;
  } else {
    cout << n - k << 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> v;
  for (int i = 0; i < m; i++) {
    cin >> v.at(i);
  }
  int k;
  k = 0;
  for (int i = 0; i < m; i++) {
    k += v.at(i);
  }
  if (n < k) {
    cout << -1 << endl;
  } else {
    cout << n - k << endl;
  }
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

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


Error: 0

Fixed submission:

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

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

int main() {
  // freopen("a.txt","r",stdin);
  int n, ar[10001], x = 0, i, j, m, sum;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> ar[i];
    x += ar[i];
  }
  sum = n - x;
  if (sum >= 0)
    cout << sum << endl;
  else
    cout << "-1\\n";
}


Error: 0

Fixed submission:

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

int main() {
  // freopen("a.txt","r",stdin);
  int n, ar[1001], x = 0, i, j, m, sum;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> ar[i];
    x += ar[i];
  }
  sum = n - x;
  if (sum >= 0)
    cout << sum << endl;
  else
    cout << "-1\\n";
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main() {
  int N, 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 += A[i];
  }
  if (N - sum >= 0)
    cout << N - sum << endl;
  else
    cout << -1 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main() {
  int N, 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 += 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 <iostream>

using namespace std;

int main() {
  long long res = 0;
  int m, n, ai;
  cin >> m >> n;
  int i = 0;
  while (i++ < n) {
    cin >> ai;
    res += ai;
  }

  cout << ((m >= res) ? (m - res) : -1) << endl;
}


Error: 30

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long long res = 0;
  int m, n, ai;
  cin >> m >> n;
  while (cin >> ai) {
    res += ai;
  }

  return (m > res) ? m - res : -1;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i, n, m, sum = 0, a[100];
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[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, sum = 0;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(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 2) >= this->size() (which is 2)


Fixed submission:

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

int main() {
  int N, M, sum = 0;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < N; i++) {
    cin >> A.at(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 <cstdio>
#include <iostream>
using namespace std;
int n, m, a[10008], i = 0;
int tot = 0;
int main() {
  cin >> n;
  cin >> m;
  for (i = 1; i <= m; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= m; i++) {
    tot += a[i];
  }
  if (tot <= n) {
    cout << n - tot;
  } else {
    cout << -1;
  }
  return 0;
}


Error: WA

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
// define #Asukaminato is cute
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.

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

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

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// define #Asukaminato is cute
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.

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

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

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

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  vector<int> vec(M);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> vec.at(i);
    // vec.push_back(i);
    N -= vec.at(i);
  }

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

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

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

  if (N >= 0)
    cout << N << 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;
  int a[10000];
  int sum = 0;
  int free_days;

  cin >> n;
  cin >> m;

  for (int i = 0; i < m; i++) {

    cin >> a[i];
  }

  for (int i = 0; i < m; i++) {

    sum = sum + a[i];
  }
  if (sum < n) {
    free_days = n - sum;
    printf("%d", free_days);
  } else if (sum == n) {

    printf("0");
  } else {
    printf("-1");
  }

  return 0;
}

Error: -11

Fixed submission:

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

int main() {

  int n, m;
  int a[n];
  int sum = 0;
  int free_days;

  cin >> n;
  cin >> m;

  for (int i = 0; i < m; i++) {

    cin >> a[i];
  }

  for (int i = 0; i < m; i++) {

    sum = sum + a[i];
  }
  if (sum < n) {
    free_days = n - sum;
    printf("%d", free_days);
  } else if (sum >= n) {

    printf("-1");
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int vac, ass, day = 0, i, rem;
  cin >> vac >> ass;
  int assi[ass + 2];
  for (i = 0; i < ass; i++) {

    cin >> assi[i];
    day = day + assi[i];
  }
  if (vac >= day)
    cout << vac - day << endl;
  else
    cout << "-1" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int vac, ass, day = 0, assi[1001];
  cin >> vac >> ass;
  for (int i = 0; i < ass; i++) {

    cin >> assi[i];
    day = day + assi[i];
  }
  if (vac >= day)
    cout << vac - day << endl;
  else
    cout << "-1" << endl;
  return 0;
}
Problem p02706 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int N = 0, M = 0;
  int x = 0;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> x;
    N -= x;
  }
  if (N >= 0)
    cout << N << endl;
  else
    cout << -1;

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int N, M;
  int ans;
  int x;
  cin >> N >> M;
  if (N > 1 && N < pow(10, 6)) {
    for (int i = 0; i < M; i++) {
      cin >> x;
      N -= x;
    }
  } else
    return -1;
  if (N > 0)
    cout << N << endl;
  else
    cout << -1;

  return 0;
}