prithivMLmods/Coder-Stat huggingface dataset:
Problem p03841 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define N 250005

using namespace std;
typedef pair<int, int> Pair;

inline int input() {
  int x;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  return x;
}

int n, num[N];
int x[N];

Pair a[N];

void Exit() {
  puts("No");
  exit(0);
}

int main() {
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
  freopen("debug", "w", stderr);

  n = input();
  for (int i = 1; i <= n; ++i) {
    x[i] = input();
    a[i].fi = x[i], a[i].se = i;
  }

  sort(a + 1, a + n + 1);

  int pos = 1, cnt;
  for (int i = 1; i <= n; ++i) {
    cnt = 0;
    if (num[a[i].fi])
      Exit();
    num[a[i].fi] = a[i].se;
    if (a[i].se == 1)
      continue;
    while (pos <= a[i].fi) {
      if (!num[pos]) {
        num[pos] = a[i].se, ++cnt;
        if (cnt == a[i].se - 1)
          break;
      }
      ++pos;
    }

    if (cnt < a[i].se - 1)
      Exit();
  }

  pos = n * n;
  for (int i = n; i; --i) {
    cnt = 0;
    if (a[i].se == n)
      continue;
    while (pos >= a[i].fi) {
      if (!num[pos]) {
        num[pos] = a[i].se, ++cnt;
        if (cnt == n - a[i].se)
          break;
      }
      --pos;
    }

    if (cnt < n - a[i].se)
      Exit();
  }

  puts("Yes");
  for (int i = 1; i < n * n; ++i)
    printf("%d ", num[i]);
  printf("%d\n", num[n * n]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
#define N 250005

using namespace std;
typedef pair<int, int> Pair;

inline int input() {
  int x;
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48))
    ;
  return x;
}

int n, num[N];
int x[N];

Pair a[N];

void Exit() {
  puts("No");
  exit(0);
}

int main() {
  n = input();
  for (int i = 1; i <= n; ++i) {
    x[i] = input();
    a[i].fi = x[i], a[i].se = i;
  }

  sort(a + 1, a + n + 1);

  int pos = 1, cnt;
  for (int i = 1; i <= n; ++i) {
    cnt = 0;
    if (num[a[i].fi])
      Exit();
    num[a[i].fi] = a[i].se;
    if (a[i].se == 1)
      continue;
    while (pos <= a[i].fi) {
      if (!num[pos]) {
        num[pos] = a[i].se, ++cnt;
        if (cnt == a[i].se - 1)
          break;
      }
      ++pos;
    }

    if (cnt < a[i].se - 1)
      Exit();
  }

  pos = n * n;
  for (int i = n; i; --i) {
    cnt = 0;
    if (a[i].se == n)
      continue;
    while (pos >= a[i].fi) {
      if (!num[pos]) {
        num[pos] = a[i].se, ++cnt;
        if (cnt == n - a[i].se)
          break;
      }
      --pos;
    }

    if (cnt < n - a[i].se)
      Exit();
  }

  puts("Yes");
  for (int i = 1; i < n * n; ++i)
    printf("%d ", num[i]);
  printf("%d\n", num[n * n]);
  return 0;
}
Problem p03841 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 505
using namespace std;
int n, x[N], a[N], cnt[N], b[N], top;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    a[x[i]] = i;
  }
  for (int i = 1; i <= n * n; i++)
    if (a[i])
      b[++top] = a[i];
  for (int i = 1; i <= n; i++)
    cnt[i] = i - 1;
  int now = 1;
  for (int i = 1; i <= n * n; i++) {
    if (!cnt[b[now]])
      now++;
    if (now != n + 1 && !a[i]) {
      a[i] = b[now];
      cnt[b[now]]--;
      if (!cnt[b[now]])
        now++;
    }
  }
  int flag = 0;
  now = n;
  for (int i = 1; i <= n; i++)
    cnt[i] = n - i;
  for (int i = n * n; i >= 1; i--) {
    if (!cnt[b[now]])
      now--;
    if (!a[i]) {
      a[i] = b[now];
      cnt[b[now]]--;
      if (!cnt[b[now]])
        now--;
    }
  }
  // for(int i=1;i<=n*n;i++)cout<<a[i]<<endl;
  // for(int i=1;i<=n*n;i++)cout<<a[i]<<endl;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= x[i]; j++)
      if (a[j] == i)
        cnt++;
    if (cnt != i)
      flag = 1;
  }
  if (flag)
    puts("No");
  else {
    puts("Yes");
    for (int i = 1; i <= n * n; i++) {
      printf("%d ", a[i]);
    }
    puts("");
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define N 505
using namespace std;
int n, x[N], a[N * N], cnt[N], b[N], top;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    a[x[i]] = i;
  }
  for (int i = 1; i <= n * n; i++)
    if (a[i])
      b[++top] = a[i];
  for (int i = 1; i <= n; i++)
    cnt[i] = i - 1;
  int now = 1;
  for (int i = 1; i <= n * n; i++) {
    if (!cnt[b[now]])
      now++;
    if (now != n + 1 && !a[i]) {
      a[i] = b[now];
      cnt[b[now]]--;
      if (!cnt[b[now]])
        now++;
    }
  }
  int flag = 0;
  now = n;
  for (int i = 1; i <= n; i++)
    cnt[i] = n - i;
  for (int i = n * n; i >= 1; i--) {
    if (!cnt[b[now]])
      now--;
    if (!a[i]) {
      a[i] = b[now];
      cnt[b[now]]--;
      if (!cnt[b[now]])
        now--;
    }
  }
  // for(int i=1;i<=n*n;i++)cout<<a[i]<<endl;
  // for(int i=1;i<=n*n;i++)cout<<a[i]<<endl;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= x[i]; j++)
      if (a[j] == i)
        cnt++;
    if (cnt != i)
      flag = 1;
  }
  if (flag)
    puts("No");
  else {
    puts("Yes");
    for (int i = 1; i <= n * n; i++) {
      printf("%d ", a[i]);
    }
    puts("");
  }
  return 0;
}
Problem p03842 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 100010;
const int Mod = 1e9 + 7;

int n;
int to[N], deg[N], pre[N];
int cnt[N], f[N];
bool vis[N];

int main() {

  scanf("%d", &n);
  For(i, 1, n) scanf("%d", &to[i]), deg[to[i]]++;
  For(i, 1, n) if (deg[i] > 2) {
    puts("0");
    return 0;
  }

  For(i, 1, n) if (deg[i] == 2 && !vis[i]) {
    int o = i;
    do {
      pre[to[o]] = o;
      vis[o] = true;
      o = to[o];
    } while (o != i);
  }

  int ans = 1;

  For(i, 1, n) if (!deg[i]) {
    int o = i, len = 0;
    while (!vis[o])
      vis[o] = true, o = to[o], ++len;

    int len2 = 0;
    do {
      o = pre[o];
      ++len2;
    } while (deg[o] == 1);

    if (len < len2)
      ans = ans * 2 % Mod;
    else if (len > len2) {
      puts("0");
      return 0;
    }
  }

  For(i, 1, n) if (!vis[i]) {
    int o = i, len = 0;
    do {
      vis[o] = true;
      o = to[o];
      ++len;
    } while (o != i);
    cnt[len]++;
  }

  For(i, 1, n) if (cnt[i]) {
    int x = i > 1 && i % 2 == 1 ? 2 : 1;
    f[0] = 1, f[1] = x;
    For(j, 2, cnt[i]) f[j] =
        (1ll * (j - 1) * i * f[j - 2] + f[j - 1] * x) % Mod;
    ans = 1ll * ans * f[cnt[i]] % Mod;
  }
  printf("%d\n", ans);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 100010;
const int Mod = 1e9 + 7;

int n;
int to[N], deg[N], pre[N];
int cnt[N], f[N];
bool vis[N];

int main() {

  scanf("%d", &n);
  For(i, 1, n) scanf("%d", &to[i]), deg[to[i]]++;
  For(i, 1, n) if (deg[i] > 2) {
    puts("0");
    return 0;
  }

  For(i, 1, n) if (deg[i] == 2 && !vis[i]) {
    int o = i;
    do {
      pre[to[o]] = o;
      if (vis[o]) {
        puts("0");
        return 0;
      }
      vis[o] = true;
      o = to[o];
    } while (o != i);
  }

  int ans = 1;

  For(i, 1, n) if (!deg[i]) {
    int o = i, len = 0;
    while (!vis[o])
      vis[o] = true, o = to[o], ++len;

    int len2 = 0;
    do {
      o = pre[o];
      ++len2;
    } while (deg[o] == 1);

    if (len < len2)
      ans = ans * 2 % Mod;
    else if (len > len2) {
      puts("0");
      return 0;
    }
  }

  For(i, 1, n) if (!vis[i]) {
    int o = i, len = 0;
    do {
      vis[o] = true;
      o = to[o];
      ++len;
    } while (o != i);
    cnt[len]++;
  }

  For(i, 1, n) if (cnt[i]) {
    int x = i > 1 && i % 2 == 1 ? 2 : 1;
    f[0] = 1, f[1] = x;
    For(j, 2, cnt[i]) f[j] =
        (1ll * (j - 1) * i * f[j - 2] + f[j - 1] * x) % Mod;
    ans = 1ll * ans * f[cnt[i]] % Mod;
  }
  printf("%d\n", ans);

  return 0;
}
Problem p03842 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>
const int N = 100007, P = 1000000007;
int a[N], deg[N], vis[N], pre[N], cnt[N], f[N];
int read() {
  int x = 0, c = getchar();
  while (isspace(c))
    c = getchar();
  while (isdigit(c))
    (x *= 10) += c & 15, c = getchar();
  return x;
}
int add(int a, int b) { return a += b - P, a + (a >> 31 & P); }
int mul(int a, int b) { return 1ll * a * b % P; }
int main() {
  int n = read(), ans = 1;
  for (int i = 1; i <= n; ++i)
    ++deg[a[i] = read()];
  for (int i = 1; i <= n; ++i) {
    if (deg[i] > 2)
      return puts("0"), 0;
    if (deg[i] < 2 || vis[i])
      continue;
    for (int p = i; !vis[p]; vis[p] = 1, pre[a[p]] = p, p = a[p])
      if (vis[p])
        return puts("0"), 0;
  }
  for (int i = 1, p, l1, l2; i <= n; ++i)
    if (!deg[i]) {
      for (p = i, l1 = 0, l2 = 0; !vis[p]; p = a[p])
        vis[p] = 1, ++l1;
      do
        ++l2, p = pre[p];
      while (deg[p] ^ 2);
      if (l1 < l2)
        ans = add(ans, ans);
      else if (l1 > l2)
        return puts("0"), 0;
    }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int p = i, l = 0;
      do
        ++l, p = a[p], vis[p] = 1;
      while (p ^ i);
      ++cnt[l];
    }
  for (int i = 1; i <= n; ans = mul(ans, f[cnt[i++]])) {
    f[0] = 1, f[1] = 1 + (i ^ 1 && i & 1);
    for (int j = 2; j <= cnt[i]; ++j)
      f[j] = add(mul(i, mul(j - 1, f[j - 2])), mul(f[1], f[j - 1]));
  }
  printf("%d", ans);
}


Fixed submission:
#include <cctype>
#include <cstdio>
const int N = 100007, P = 1000000007;
int a[N], deg[N], vis[N], pre[N], cnt[N], f[N];
int read() {
  int x = 0, c = getchar();
  while (isspace(c))
    c = getchar();
  while (isdigit(c))
    (x *= 10) += c & 15, c = getchar();
  return x;
}
int add(int a, int b) { return a += b - P, a + (a >> 31 & P); }
int mul(int a, int b) { return 1ll * a * b % P; }
int main() {
  int n = read(), ans = 1;
  for (int i = 1; i <= n; ++i)
    ++deg[a[i] = read()];
  for (int i = 1; i <= n; ++i) {
    if (deg[i] > 2)
      return puts("0"), 0;
    if (deg[i] < 2 || vis[i])
      continue;
    // for(int p=i;!vis[p];vis[p]=1,pre[a[p]]=p,p=a[p]) if(vis[p]) return
    // puts("0"),0;
    int p = i;
    do {
      if (vis[p]) {
        printf("0\n");
        return 0;
      }
      vis[p] = 1, pre[a[p]] = p, p = a[p];
    } while (p != i);
  }
  for (int i = 1, p, l1, l2; i <= n; ++i)
    if (!deg[i]) {
      for (p = i, l1 = 0, l2 = 0; !vis[p]; p = a[p])
        vis[p] = 1, ++l1;
      do
        ++l2, p = pre[p];
      while (deg[p] ^ 2);
      if (l1 < l2)
        ans = add(ans, ans);
      else if (l1 > l2)
        return puts("0"), 0;
    }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int p = i, l = 0;
      do
        ++l, p = a[p], vis[p] = 1;
      while (p ^ i);
      ++cnt[l];
    }
  for (int i = 1; i <= n; ans = mul(ans, f[cnt[i++]])) {
    f[0] = 1, f[1] = 1 + (i ^ 1 && i & 1);
    for (int j = 2; j <= cnt[i]; ++j)
      f[j] = add(mul(i, mul(j - 1, f[j - 2])), mul(f[1], f[j - 1]));
  }
  printf("%d", ans);
}
Problem p03844 (Python)

Buggy submission (status: Runtime Error):
a, op, b = [int(i) for i in input().split()]
if op == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))


Fixed submission:
a, op, b = [i for i in input().split()]
if op == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))
Problem p03844 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  char op;
  cin >> op;
  cin >> b;
  if (op == '+')
    cout << a + b;
  else
    return a - b;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a;
  char op;
  cin >> op;
  cin >> b;
  if (op == '+')
    cout << a + b;
  else
    cout << a - b;
  return 0;
}
Problem p03844 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>

int main() {
  int N;
  scanf("%d\n", &N);
  int T[100];
  for (int i = 0; i < N; i++)
    scanf(" %d", &T[i]);
  int M;
  scanf("\n%d\n", &M);
  int P[100], X[100];
  for (int i = 0; i < M; i++)
    scanf("%d %d\n", &P[i], &X[i]);
  int sum = 0;
  for (int i = 0; i < N; i++)
    sum += T[i];
  for (int i = 0; i < M; i++)
    printf("%d\n", sum - T[P[i]] + X[i]);
  return 0;
}


Fixed submission:
#include <cstdio>

int main() {
  int A, B;
  char op;
  scanf("%d %c %d", &A, &op, &B);
  printf("%d\n", op == '+' ? A + B : A - B);
  return 0;
}
Problem p03844 (Python)

Buggy submission (status: Runtime Error):
A, op, B = input().split()
if op == "+":
    print(A + B)
else:
    print(A - B)


Fixed submission:
A, op, B = input().split()
A = int(A)
B = int(B)
if op == "+":
    print(A + B)
else:
    print(A - B)
Problem p03844 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  char s[7];
  cin >> s;
  for (int i = 0; i <= 6; i++)
    if (s[i] == '1')
      ans++;
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  char op;
  cin >> a >> op >> b;
  if (op == '+')
    cout << a + b << endl;
  else
    cout << a - b << endl;
  return 0;
}
Problem p03844 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int a, b;
  char c;
  cin >> a >> c >> b;
  if (c == '-')
    b = -b;
  cout << a + b << '\n';
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
#endif
  int a, b;
  char c;
  cin >> a >> c >> b;
  if (c == '-')
    b = -b;
  cout << a + b << '\n';
}
Problem p03844 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<ll> t(n);
  ll sum = 0;
  rep(i, n) {
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  vector<ll> p(m), x(m);
  rep(i, m) cin >> p[i] >> x[i];
  vector<ll> ans(m);
  rep(i, m) {
    ans[i] = sum - t[p[i] - 1] + x[i];
    cout << ans[i] << "\n";
  }
  return 0;
}

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

int main() {
  int a, b;
  char op;
  cin >> a >> op >> b;

  if (op == '+')
    cout << a + b << "\n";
  else
    cout << a - b << "\n";
  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int N, T[101], M, P[101], X[101], sum = 0, p[101];
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  for (int i = 1; i <= M; i++) {
    cin >> P[i] >> X[i];
  }
  for (int i = 1; i <= N; i++) {
    p[i] = sum - T[P[i]] + X[i];
    cout << p[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int N, T[101], M, P[101], X[101], sum = 0, p[101];
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  for (int i = 1; i <= M; i++) {
    cin >> P[i] >> X[i];
  }
  for (int i = 1; i <= M; i++) {
    p[i] = sum - T[P[i]] + X[i];
    cout << p[i] << endl;
  }
  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M, total = 0;
  cin >> N;
  int T[N];
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    total += T[i];
  }
  cin >> M;
  int P[M], X[M];
  for (int i = 0; i < M; i++)
    cin >> P[i] >> X[i];

  for (int i = 0; i < N; i++) {
    cout << total - T[P[i] - 1] + X[i] << endl;
  }
}

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

int main() {
  int N, M, total = 0;
  cin >> N;
  int T[N];
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    total += T[i];
  }
  cin >> M;
  int P[M], X[M];
  for (int i = 0; i < M; i++)
    cin >> P[i] >> X[i];

  for (int i = 0; i < M; i++) {
    cout << total - T[P[i] - 1] + X[i] << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s)                                                             \
  for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int> a(n)
#define PQ(a) priority_queue<int> a
#define PQmin(a) priority_queue<int, : vector<int>, greater<int>> a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N;
  int T[N];
  rep(i, N) cin >> T[i];
  cin >> M;
  int P[M], X[M];
  rep(i, M) cin >> P[M] >> X[M];
  int sum = 0;
  rep(i, N) sum += T[i];
  rep(i, M) { cout << sum - T[P[i] - 1] + X[i] << endl; }
}


Fixed submission:
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s)                                                             \
  for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int> a(n)
#define PQ(a) priority_queue<int> a
#define PQmin(a) priority_queue<int, : vector<int>, greater<int>> a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N;
  int T[N];
  rep(i, N) cin >> T[i];
  cin >> M;
  int P[M], X[M];
  rep(i, M) cin >> P[i] >> X[i];
  int sum = 0;
  rep(i, N) sum += T[i];
  rep(i, M) { cout << sum - T[P[i] - 1] + X[i] << endl; }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

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

int main() {
  int N, M;
  cin >> N;
  int ans = 0;
  int A[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    ans += A[i];
  }
  cin >> M;
  int B[M + 1], C[M + 1];
  for (int i = 1; i <= M; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 1; i <= M; i++) {
    cout << ans - (A[B[i]] - C[i]) << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):

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

int main() {
  int n; // 問題数
  cin >> n;

  vector<int> time; // 各問題を解くのにかかる時間
  for (int i = 0; i < n; i++) {
    cin >> time.at(i);
  }
  // 元々の合計時間
  int sum;
  sum = accumulate(time.begin(), time.end(), 0);

  int m;
  cin >> m; // ドリンクの数

  for (int i = 0; i < m; i++) {
    int ans, p, x;
    cin >> p >> x;
    ans = sum + x - time.at(p - 1);
    cout << ans << endl;
  }
}

Fixed submission:

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

int main() {
  int n; // 問題数
  cin >> n;

  vector<int> time(n); // 各問題を解くのにかかる時間
  for (int i = 0; i < n; i++) {
    cin >> time.at(i);
  }
  // 元々の合計時間
  int sum;
  sum = accumulate(time.begin(), time.end(), 0);

  int m;
  cin >> m; // ドリンクの数

  for (int i = 0; i < m; i++) {
    int ans, p, x;
    cin >> p >> x;
    ans = sum + x - time.at(p - 1);
    cout << ans << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M, tmp;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++) {
    int sum = 0;
    cin >> P.at(i) >> X.at(i);
    tmp = T.at(i);
    T.at(P.at(i) - 1) = X.at(i);
    for (int j = 0; j < T.size(); j++) {
      sum += T.at(j);
    }
    cout << sum << endl;
    T.at(P.at(i) - 1) = tmp;
  }
}

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

int main() {
  int N, M, tmp;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++) {
    int sum = 0;
    cin >> P.at(i) >> X.at(i);
    tmp = T.at(P.at(i) - 1);
    T.at(P.at(i) - 1) = X.at(i);
    for (int j = 0; j < T.size(); j++) {
      sum += T.at(j);
    }
    cout << sum << endl;
    T.at(P.at(i) - 1) = tmp;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;

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

  int M;
  cin >> M;

  vector<vector<int>> drink(M, vector<int>(2, 0));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> drink[i][j];
    }
  }

  for (int i = 0; i < M; i++) {
    int ans = 0;
    for (int j = 0; j < N; j++) {
      ans += time[j];
    }
    ans += drink[i][1] - time[drink[i][1] - 1];

    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;

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

  int M;
  cin >> M;

  vector<vector<int>> drink(M, vector<int>(2, 0));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> drink[i][j];
    }
  }

  for (int i = 0; i < M; i++) {
    int ans = 0;
    for (int j = 0; j < N; j++) {
      ans += time[j];
    }
    ans += drink[i][1] - time[drink[i][0] - 1];

    cout << ans << endl;
  }

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> Q(N);
  int T = 0;
  for (int i = 0; i < N; i++) {
    cin >> Q.at(i);
    T += Q.at(i);
  }
  int M;
  cin >> M;
  vector<vector<int>> D(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> D.at(i).at(j);
    }
  }
  for (int i = 0; i < N; i++) {
    T -= Q.at(D.at(i).at(0) - 1);
    cout << T + D.at(i).at(1) << endl;
    T += Q.at(D.at(i).at(0) - 1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> Q(N);
  int T = 0;
  for (int i = 0; i < N; i++) {
    cin >> Q.at(i);
    T += Q.at(i);
  }
  int M;
  cin >> M;
  vector<vector<int>> D(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> D.at(i).at(j);
    }
  }
  for (int i = 0; i < M; i++) {
    T -= Q.at(D.at(i).at(0) - 1);
    cout << T + D.at(i).at(1) << endl;
    T += Q.at(D.at(i).at(0) - 1);
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  for (int i = 0; i < n; i++)
    cin >> t[i];
  int m;
  cin >> m;
  vector<pair<int, int>> d(m);
  for (int i = 0; i < m; i++)
    cin >> d[i].first >> d[i].second;
  int ans = 0;
  for (int i = 0; i < n; i++)
    ans = min(ans, ans - (t[d[i].first - 1] - d[i].second));
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  for (int i = 0; i < n; i++)
    cin >> t[i];
  int m;
  cin >> m;
  vector<pair<int, int>> d(m);
  for (int i = 0; i < m; i++)
    cin >> d[i].first >> d[i].second;
  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += t[i];
  for (int i = 0; i < m; i++)
    cout << ans - (t[d[i].first - 1] - d[i].second) << endl;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  // 入力
  int N, M;
  cin >> N;

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

  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++) {
    cin >> P.at(i) >> X.at(i);
  }

  // 全部の問題をドリンクなしで解くのにかかる時間
  int time_all = 0;
  for (int i = 0; i < N; i++) {
    time_all += T.at(i);
  }

  // 出力
  for (int i = 0; i < M; i++) {
    cout << time_all - (T.at(P.at(i))) - X.at(i) << endl;
  }
}

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

int main() {
  // 入力
  int N, M;
  cin >> N;

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

  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++) {
    cin >> P.at(i) >> X.at(i);
  }

  // 全部の問題をドリンクなしで解くのにかかる時間
  int time_all = 0;
  for (int i = 0; i < N; i++) {
    time_all += T.at(i);
  }

  // 出力
  for (int i = 0; i < M; i++) {
    cout << time_all - (T.at(P.at(i) - 1) - X.at(i)) << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end());
#define vecmin(A) *min_element(A.begin(), A.end());
#define vecmax(A) *max_element(A.begin(), A.end());
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int sum = 0;
  rep(i, n) {
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  vector<int> dif(m);
  rep(i, n) {
    int p, x;
    cin >> p >> x;
    dif[i] = t[p - 1] - x;
  }
  rep(i, m) { cout << sum - dif[i] << endl; }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end());
#define vecmin(A) *min_element(A.begin(), A.end());
#define vecmax(A) *max_element(A.begin(), A.end());
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int sum = 0;
  rep(i, n) {
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  vector<int> dif(m);
  rep(i, m) {
    int p, x;
    cin >> p >> x;
    dif[i] = t[p - 1] - x;
  }
  rep(i, m) { cout << sum - dif[i] << endl; }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  int M;
  cin >> M;
  vector<int> P(N), X(N);
  for (int i = 0; i < M; i++) {
    cin >> P.at(i) >> X.at(i);
  }
  long long sum;
  for (int i = 0; i < M; i++) {
    sum = 0;
    for (int j = 0; j < N; j++) {
      if (j != P.at(i) - 1) {
        sum += T.at(j);
      } else {
        sum += X.at(i);
      }
    }
    cout << sum << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  int M;
  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++) {
    cin >> P.at(i) >> X.at(i);
  }
  long long sum;
  for (int i = 0; i < M; i++) {
    sum = 0;
    for (int j = 0; j < N; j++) {
      if (j != P.at(i) - 1) {
        sum += T.at(j);
      } else {
        sum += X.at(i);
      }
    }
    cout << sum << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SUM(c) accumulate((c).begin(), (c).end(), 0)

int main() {
  int n, m, k, l;
  vector<int> t, p, x;
  cin >> n;
  REP(i, n) {
    cin >> k;
    t.push_back(k);
  }
  cin >> m;
  REP(i, n) {
    cin >> k >> l;
    p.push_back(k - 1);
    x.push_back(l);
  }
  int totaltime = 0;
  REP(i, n) { totaltime += t[i]; }
  REP(i, m) { cout << totaltime - t[p[i]] + x[i] << endl; }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SUM(c) accumulate((c).begin(), (c).end(), 0)

int main() {
  int n, m, k, l;
  vector<int> t, p, x;
  cin >> n;
  REP(i, n) {
    cin >> k;
    t.push_back(k);
  }
  cin >> m;
  REP(i, m) {
    cin >> k >> l;
    p.push_back(k - 1);
    x.push_back(l);
  }
  int totaltime = 0;
  REP(i, n) { totaltime += t[i]; }
  REP(i, m) { cout << totaltime - t[p[i]] + x[i] << endl; }

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;

  vector<ll> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }

  int m;
  cin >> m;

  vector<int> p(n);
  vector<ll> x(n);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }

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

    ll tmpSum = 0;
    for (int j = 0; j < n; j++) {

      if (j == p[i] - 1)
        tmpSum += x[i];
      else
        tmpSum += t[j];
    }
    cout << tmpSum << endl;
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;

  vector<ll> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }

  int m;
  cin >> m;

  vector<int> p(m);
  vector<ll> x(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }

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

    ll tmpSum = 0;
    for (int j = 0; j < n; j++) {

      if (j == p[i] - 1)
        tmpSum += x[i];
      else
        tmpSum += t[j];
    }
    cout << tmpSum << endl;
  }

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    sum += T.at(i);
  }
  int M, p, x;
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> p >> x;
    cout << sum + (x - T.at(p));
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    sum += T.at(i);
  }
  int M, p, x;
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> p >> x;
    cout << sum + (x - T.at(p - 1)) << endl;
    ;
  }
  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N;
  cin >> N;
  ll T[N];
  ll sum = 0;
  rep(i, N) {
    cin >> T[i];
    sum += T[i];
  }
  ll M;
  cin >> M;
  ll P[M], X[M];
  rep(i, N) cin >> P[i] >> X[i];

  for (int i = 0; i < M; i++) {
    ll ans = sum;
    ans -= T[P[i] - 1];
    ans += X[i];
    cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N;
  cin >> N;
  ll T[N];
  ll sum = 0;
  rep(i, N) {
    cin >> T[i];
    sum += T[i];
  }
  ll M;
  cin >> M;
  ll P[M], X[M];
  rep(i, M) cin >> P[i] >> X[i];

  for (int i = 0; i < M; i++) {
    ll ans = sum;
    ans -= T[P[i] - 1];
    ans += X[i];
    cout << ans << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream> // istringstream
#include <string>
#include <vector>

using namespace std;

int main() {
  // 練習でやった問題, 逆から探索する
  int N;
  cin >> N;
  int T[N];
  for (int i = 0; i < N; ++i)
    cin >> T[i];
  int M;
  cin >> M;
  int P[M], X[M];
  for (int i = 0; i < N; ++i)
    cin >> P[i] >> X[i];

  int ans[M];

  for (int i = 0; i < M; ++i) {
    ans[i] = X[i] - T[P[i] - 1];
    for (int j = 0; j < N; ++j) {
      ans[i] += T[j];
    }
  }

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

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream> // istringstream
#include <string>
#include <vector>

using namespace std;

int main() {
  // 練習でやった問題, 逆から探索する
  int N;
  cin >> N;
  int T[N];
  for (int i = 0; i < N; ++i)
    cin >> T[i];
  int M;
  cin >> M;
  int P[M], X[M];
  for (int i = 0; i < M; ++i)
    cin >> P[i] >> X[i];

  int ans[M];

  for (int i = 0; i < M; ++i) {
    ans[i] = X[i] - T[P[i] - 1];
    for (int j = 0; j < N; ++j) {
      ans[i] += T[j];
    }
  }

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

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):

#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int T[N];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    ans += (long long)T[i];
  }
  int M;
  cin >> M;
  int P[N], X[N];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; i++) {
    cout << ans - (long long)T[P[i] - 1] + (long long)X[i] << endl;
  }

  return 0;
}

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int T[N];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    ans += (long long)T[i];
  }
  int M;
  cin >> M;
  int P[M], X[M];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; i++) {
    cout << ans - (long long)T[P[i] - 1] + (long long)X[i] << endl;
  }

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {

  int n, m, sum;
  cin >> n;
  int t[n], p[n], x[n];

  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    sum += t[i];
  }

  cin >> m;

  for (int i = 1; i <= m; i++) {
    cin >> p[i] >> x[i];
    cout << sum - t[p[i]] + x[i] << endl;
  }
}

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

int main() {

  int n, m, sum;
  cin >> n;
  int t[102], p[102], x[102];

  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    sum += t[i];
  }

  cin >> m;

  for (int i = 1; i <= m; i++) {
    cin >> p[i] >> x[i];
    cout << sum - t[p[i]] + x[i] << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N;
  vector<int> T(N), P(M), X(M);
  for (int i = 1; i <= N; i++) {
    cin >> T[i];
  }
  cin >> M;
  for (int i = 1; i <= M; i++) {
    cin >> P[i] >> X[i];
  }
  int sum = 0;
  int ans;
  for (int i = 1; i <= N; i++) {
    sum += T[i];
  }
  for (int i = 1; i <= M; i++) {
    ans = sum;
    ans = ans - T[P[i]] + X[i];
    cout << ans << endl;
  }
}

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

int main() {
  int N, M;
  cin >> N;
  vector<int> T(110), P(110), X(110);
  for (int i = 1; i <= N; i++) {
    cin >> T[i];
  }
  cin >> M;
  for (int i = 1; i <= M; i++) {
    cin >> P[i] >> X[i];
  }
  int sum = 0;
  int ans;
  for (int i = 1; i <= N; i++) {
    sum += T[i];
  }
  for (int i = 1; i <= M; i++) {
    ans = sum;
    ans = ans - T[P[i]] + X[i];
    cout << ans << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int total = 0;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    total += T.at(i);
  }
  int M;
  cin >> M;
  vector<pair<int, int>> P(M);
  for (int i = 0; i < M; i++) {
    cin >> P.at(i).first >> P.at(i).second;
  }
  for (int i = 0; i < M; i++) {
    cout << total - T.at(P.at(i).first) + P.at(i).second << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  int total = 0;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    total += T.at(i);
  }
  int M;
  cin >> M;
  vector<pair<int, int>> P(M);
  for (int i = 0; i < M; i++) {
    cin >> P.at(i).first >> P.at(i).second;
  }
  for (int i = 0; i < M; i++) {
    cout << total - T.at(P.at(i).first - 1) + P.at(i).second << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

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

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

  for (int i = 0; i < M; i++) {
    cout << sum - (T.at(P.at(i) - 1) - X.at(i)) << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

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

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

  for (int i = 0; i < M; i++) {
    cout << sum - (T.at(P.at(i) - 1) - X.at(i)) << endl;
  }
  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(void) {
  int N, M, sum = 0;
  cin >> N;
  int T[N];
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  int P[N], X[M];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
    cout << sum + X[i] - T[P[i] - 1] << endl;
  }
  return 0;
}

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

int main(void) {
  int N, M, sum = 0;
  cin >> N;
  int T[N];
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  cin >> M;
  int P[M], X[M];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
    cout << sum + X[i] - T[P[i] - 1] << endl;
  }
  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define mod 1000000007
#define inf 1e18

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int t;
  cin >> t;
  int time[t], copyTime[t];
  for (int i = 0; i < t; ++i) {
    cin >> time[i];
  }

  copy(time, time + t, copyTime);

  int m;
  cin >> m;
  pair<int, int> drink[m];
  for (int i = 0; i < m; ++i) {
    cin >> drink[i].first >> drink[i].second;
  }

  for (int i = 0; i < m; ++i) {
    int fir = drink[i].first;
    int sec = drink[i].second;

    time[fir - 1] = sec;
    long long sum = 0;
    for (int j = 0; j < t; ++j) {
      sum += time[j];
    }

    cout << sum << endl;
    copy(copyTime, copyTime + t, time);
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define mod 1000000007
#define inf 1e18

int main() {
  int t;
  cin >> t;
  int time[t], copyTime[t];
  for (int i = 0; i < t; ++i) {
    cin >> time[i];
  }

  copy(time, time + t, copyTime);

  int m;
  cin >> m;
  pair<int, int> drink[m];
  for (int i = 0; i < m; ++i) {
    cin >> drink[i].first >> drink[i].second;
  }

  for (int i = 0; i < m; ++i) {
    int fir = drink[i].first;
    int sec = drink[i].second;

    time[fir - 1] = sec;
    long long sum = 0;
    for (int j = 0; j < t; ++j) {
      sum += time[j];
    }

    cout << sum << endl;
    copy(copyTime, copyTime + t, time);
  }

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for (int i = 0; i < M; i++)
    cin >> P[i] >> X[i];
  vector<int> result(N);
  for (int i = 0; i < M; i++)
    result[i] = sum - T[P[i] - 1] + X[i];
  for (int i = 0; i < M; i++)
    cout << result[i] << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for (int i = 0; i < M; i++)
    cin >> P[i] >> X[i];
  vector<int> result(M);
  for (int i = 0; i < M; i++)
    result[i] = sum - T[P[i] - 1] + X[i];
  for (int i = 0; i < M; i++)
    cout << result[i] << endl;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M, sum = 0;
  cin >> N;
  vector<int> t(N), p(M), x(M);

  for (int i = 0; i < N; i++) {
    cin >> t.at(i);
    sum += t.at(i);
  }

  cin >> M;

  for (int i = 0; i < M; i++) {
    cin >> p.at(i) >> x.at(i);
    int ans = sum - t.at(p.at(i)) + x.at(i);
    cout << ans << endl;
  }
}

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

int main() {
  int N, M, sum = 0;
  cin >> N;
  vector<int> t(N), p(M), x(M);

  for (int i = 0; i < N; i++) {
    cin >> t.at(i);
    sum += t.at(i);
  }

  cin >> M;

  for (int i = 0; i < M; i++) {
    cin >> p.at(i) >> x.at(i);
    int ans = sum - t.at(p.at(i) - 1) + x.at(i);
    cout << ans << endl;
  }
}
Problem p03845 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  rep(i, N) cin >> T[i];
  int M;
  cin >> M;
  vector<int> P(N), X(N);
  rep(i, M) {
    cin >> P[i];
    cin >> X[i];
  }

  int sum = 0;
  rep(i, N) sum += T[i];

  rep(i, M) {
    int ans = sum;
    ans -= T[P[i] - 1];
    ans += X[i];
    cout << ans << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  rep(i, N) cin >> T[i];
  int M;
  cin >> M;
  vector<int> P(M), X(M);
  rep(i, M) {
    cin >> P[i];
    cin >> X[i];
  }

  int sum = 0;
  rep(i, N) sum += T[i];

  rep(i, M) {
    int ans = sum;
    ans -= T[P[i] - 1];
    ans += X[i];
    cout << ans << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int p, x;
    cin >> p >> x;
    int temp = a[p - 1];
    a[p - 1] = x;
    int sum = 0;
    for (int i = 0; i < n; i++)
      sum += a[i];
    cout << sum << "\n";
    a[p - 1] = temp;
  }
  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  int SUM = 0;
  for (int i = 0; i < N; i++) {
    SUM += T.at(i);
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int P, X;
    cin >> P >> X;
    cout << SUM - T.at(P - 1) + X << endl;
  }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
  }
  int SUM = 0;
  for (int i = 0; i < N; i++) {
    SUM += T.at(i);
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int P, X;
    cin >> P >> X;
    cout << SUM - T.at(P - 1) + X << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, S = 0, P, X;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    S += T.at(i);
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> P >> X;
    cout << S - T.at(P) + X << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, S = 0, P, X;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    S += T.at(i);
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> P >> X;
    cout << S - T.at(P - 1) + X << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;

int main() {
  int N;
  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; ++i) {
    int p, x;
    cin >> p >> x;
    cout << sum - T[p - 1] + x << endl;
  }
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; ++i) {
    int p, x;
    cin >> p >> x;
    cout << sum - T[p - 1] + x << endl;
  }
  return 0;
}