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

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

int main() {
  // get a integer
  int a, b, c, x;
  int max_a, max_b, max_c;
  int count = 0;
  cin >> a >> b >> c >> x;
  max_a = x / a;
  max_b = x / b;
  max_c = x / c;

  for (int i = 0; i <= max_a; i++) {
    for (int j = 0; j <= max_b; j++) {
      for (int k = 0; k <= max_c; k++) {
        if ((500 * i + 100 * j + 50 * k) == x) {
          count++;
        }
      }
    }
  }
  cout << count;
  return 0;
}

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

int main() {
  // get a integer
  int a, b, c, x;
  int max_a, max_b, max_c;
  int count = 0;
  cin >> a >> b >> c >> x;
  max_a = x / 500 < a ? x / 500 : a;
  max_b = x / 100 < b ? x / 100 : b;
  max_c = x / 50 < c ? x / 50 : c;

  for (int i = 0; i <= max_a; i++) {
    for (int j = 0; j <= max_b; j++) {
      for (int k = 0; k <= max_c; k++) {
        if ((500 * i + 100 * j + 50 * k) == x) {
          count++;
        }
      }
    }
  }
  cout << count;
  return 0;
}
Problem p03448 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#pragma warning(disable : 4996)
FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
// FILE *in = stdin, *out = stdout;
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define INF 1e18
#define NM 20005
#define MOD 1000000000
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define si(n) fscanf(in, "%d", &n)
#define sd(n) fscanf(in, "%lf", &n)
typedef long long int ll;
int main() {
  int A, B, C, X, ans = 0;
  si(A), si(B), si(C), si(X);
  FOR(i, 0, A) FOR(j, 0, B) FOR(k, 0, C) {
    if (500 * i + 100 * j + 50 * k == X)
      ans++;
  }
  fprintf(out, "%d", ans);
  return 0;
}

Fixed submission:
#include <stdio.h>
#pragma warning(disable : 4996)
// FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define INF 1e18
#define NM 20005
#define MOD 1000000000
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define si(n) fscanf(in, "%d", &n)
#define sd(n) fscanf(in, "%lf", &n)
typedef long long int ll;
int main() {
  int A, B, C, X, ans = 0;
  si(A), si(B), si(C), si(X);
  FOR(i, 0, A) FOR(j, 0, B) FOR(k, 0, C) {
    if (500 * i + 100 * j + 50 * k == X)
      ans++;
  }
  fprintf(out, "%d", ans);
  return 0;
}
Problem p03448 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int res = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; i <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        if (i * 500 + j * 100 + k * 50 == x)
          ++res;
      }
    }
  }
  cout << res;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int res = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      for (int k = 0; k <= c; ++k) {
        if (i * 500 + j * 100 + k * 50 == x)
          ++res;
      }
    }
  }
  cout << res;
}
Problem p03448 (C++)

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

using namespace std;

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; i <= B; j++) {
      for (int k = 0; k <= C; k++) {
        if (i * 500 + j * 100 + k * 50 == X)
          cnt++;
      }
    }
  }
  cout << cnt;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        if (i * 500 + j * 100 + k * 50 == X)
          cnt++;
      }
    }
  }
  cout << cnt;
}
Problem p03448 (C++)

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int cnt = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; i <= B; j++) {
      for (int k = 0; i <= C; k++) {
        if (500 * i + 100 * j + 50 * k == X) {
          cnt += 1;
        }
      }
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int cnt = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        if (500 * i + 100 * j + 50 * k == X) {
          cnt += 1;
        }
      }
    }
  }
  cout << cnt << endl;
}
Problem p03448 (C++)

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

int main() {
  int A, B, C, X;
  int count = 0, keep = 0;
  int i, j, k, price = 0;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  // 500 coin 0 ~ A
  for (i = 0; i <= A; i++) {
    // 100 coin 0 ~ B
    for (j = 0; j <= B; j++) {
      // 50  coin 0 ~ C
      for (j = 0; j <= C; k++) {
        price = 500 * i + 100 * j + 50 * k;
        if (price == X)
          count++;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int A, B, C, X;
  int count = 0, keep = 0;
  int i, j, k, price = 0;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  // 500 coin 0 ~ A
  for (i = 0; i <= A; i++) {
    // 100 coin 0 ~ B
    for (j = 0; j <= B; j++) {
      // 50  coin 0 ~ C
      for (k = 0; k <= C; k++) {
        price = 500 * i + 100 * j + 50 * k;
        if (price == X)
          count++;
      }
    }
  }
  cout << count << endl;
}
Problem p03448 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++A) {
    for (int b = 0; b <= B; ++B) {
      for (int c = 0; c <= C; ++C) {
        int total = 500 * a + 100 * b + 50 * c;
        if (total == X)
          ++res;
      }
    }
  }
  cout << res << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500 * a + 100 * b + 50 * c;
        if (total == X)
          ++res;
      }
    }
  }
  cout << res << endl;
}
Problem p03448 (C++)

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

using namespace std;

int main() {
  int a, b, c, i, j, k, l, n, cnt = 0;
  vector<int> v;

  cin >> a >> b >> c >> n;
  for (i = 0; i <= a; i++) {
    for (j = 0; j <= b; j++) {
      for (k = 0; k <= c; k++) {
        l = i * 500 + j * 100 + k * 50;
        v.push_back(l);
      }
    }
  }

  for (i = 0; i = v.size(); i++) {
    if (v[i] == n)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int a, b, c, i, j, k, l, n, cnt = 0;
  vector<int> v;

  cin >> a >> b >> c >> n;
  for (i = 0; i <= a; i++) {
    for (j = 0; j <= b; j++) {
      for (k = 0; k <= c; k++) {
        l = i * 500 + j * 100 + k * 50;
        v.push_back(l);
      }
    }
  }

  for (i = 0; i < v.size(); i++) {
    if (v[i] == n)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03448 (Python)

Buggy submission (status: Runtime Error):
x500 = int(input())
x100 = int(input())
x50 = int(input())
xxx = int(input())

i = 0
j = 0
k = 0


def judge(sum, xxx):
    sum = 500 * i + 100 * j + 50 * k
    return sum == xxx and sum <= 2000


count = 0
for i in range(x500):
    if judge(i, j, k):
        count += 1
    for j in range(x100):
        if judge(i, j, k):
            count += 1
        for k in range(x50):
            if judge(i, j, k):
                count += 1
print(count)


Fixed submission:
A, B, C, x = [int(input()) for i in range(4)]
print(
    sum(
        500 * a + 100 * b + 50 * c == x
        for a in range(A + 1)
        for b in range(B + 1)
        for c in range(C + 1)
    )
)
Problem p03448 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int sum = 0;
  for (int A = 0; A <= a; a++) {
    for (int B = 0; B <= b; b++) {
      for (int C = 0; C <= c; c++) {
        int X = 500 * A + 100 * B + 50 * C;
        if (X == x)
          sum++;
      }
    }
  }
  cout << sum << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int sum = 0;
  for (int A = 0; A <= a; A++) {
    for (int B = 0; B <= b; B++) {
      for (int C = 0; C <= c; C++) {
        int X = 500 * A + 100 * B + 50 * C;
        if (X == x)
          sum++;
      }
    }
  }
  cout << sum << endl;
}
Problem p03448 (C++)

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

int main() {
  int X, A, B, C, a, count;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; i <= B; j++) {
      for (int k = 0; i <= C; k++) {
        a = 500 * i + 100 * j + 50 * k;
        if (a == X) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


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

int main() {
  int X, A, B, C, a, count;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        a = 500 * i + 100 * j + 50 * k;
        if (a == X) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
Problem p03448 (C++)

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

using namespace std;
#define PI acos(-1)

int main() {
  int A, B, C, X;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;

  int num = 0;

  for (int a = 0; a <= (X / A); a++) {
    for (int b = 0; b <= (X / B); b++) {
      for (int c = 0; C <= (X / C); c++) {
        if ((500 * a + 100 * b + 50 * c) == X) {
          num++;
        }

        if ((500 * a + 100 * b + 50 * c) > X) {
          break;
        }
      }
    }
  }

  cout << num;
}


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

using namespace std;
#define PI acos(-1)

int main() {
  int A, B, C, X;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;

  int num = 0;

  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        if ((500 * a + 100 * b + 50 * c) == X) {
          num++;
        }

        if ((500 * a + 100 * b + 50 * c) > X) {
          break;
        }
      }
    }
  }

  cout << num;
}
Problem p03448 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int i = 0; i <= A / 500; i++) {
    for (int j = 0; j <= B / 100; j++) {
      for (int k = 0; j <= C / 50; k++) {
        if (i * 500 + B * 100 + C * 50 == X)
          res++;
      }
    }
  }
  cout << res;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      int k = (X - i * 500 - j * 100) / 50;
      if (0 <= k && k <= C)
        res++;
    }
  }
  cout << res;
}
Problem p03448 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

  cin >> N >> M >> K;
  cin >> L;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      for (int k = 0; k <= K; K++) {
        if (i * 500 + j * 100 + k * 50 == L) {
          R++;
        }
      }
    }
  }
  cout << R << endl;
  return 0;
}

Fixed submission:
#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

  cin >> N >> M >> K;
  cin >> L;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      for (int k = 0; k <= K; k++) {
        if (i * 500 + j * 100 + k * 50 == L) {
          R++;
        }
      }
    }
  }
  cout << R << endl;
  return 0;
}
Problem p03448 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int A, B, C, X, count = 0;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; j <= C; k++) {
        if (X == 500 * i + 100 * j + 50 * k)
          count++;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int A, B, C, X, count = 0;
  cin >> A >> B >> C >> X;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        if (X == 500 * a + 100 * b + 50 * c)
          ++count;
      }
    }
  }
  cout << count << endl;
}
Problem p03448 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int A, B, C, X, count = 0;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= floor(X / A); i++) {
    for (int j = 0; j <= floor(X / A); j++) {
      for (int k = 0; k <= floor(X / A); k++)
        if (i * 500 + j * 100 + k * 50 == X) {
          count++;
          break;
        }
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int A, B, C, X, count = 0;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++)
        if (i * 500 + j * 100 + k * 50 == X) {
          count++;
          break;
        }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03448 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i <= int(n); i++)
#define mod 1000000007

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; i++) {
      for (int k = 0; k <= C; i++) {
        int sum = (i * 500) + (j * 100) + (k * 50);
        if (sum == X) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i <= int(n); i++)
#define mod 1000000007

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        int sum = (i * 500) + (j * 100) + (k * 50);
        if (sum == X) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}
Problem p03448 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> A(100000000);
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int l = 0; l <= c; l++) {
        A.at(i * 500 + j * 100 + l * 50)++;
      }
    }
  }
  int ob;
  cin >> ob;
  cout << A.at(ob) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> A(100000);
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int l = 0; l <= c; l++) {
        A.at(i * 500 + j * 100 + l * 50)++;
      }
    }
  }
  int ob;
  cin >> ob;
  cout << A.at(ob) << endl;
}
Problem p03448 (C++)

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

int main() {
  int A, B, C, X, i, j, k, count = 0;

  cin >> A >> B >> C >> X;

  for (i = 0; i < A; i++) {
    for (j = 0; j < B; j++) {
      for (k = 0; k < C; k++) {
        if ((X % (500 * i + 100 * j + 50 * k)) == 0)
          count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}

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

int main() {
  int A, B, C, X, i, j, k, count = 0;

  cin >> A >> B >> C >> X;

  for (i = 0; i <= A; i++) {
    for (j = 0; j <= B; j++) {
      for (k = 0; k <= C; k++) {
        if (X == 500 * i + 100 * j + 50 * k)
          count++;
      }
    }
  }

  cout << count << endl;

  return 0;
}
Problem p03448 (Python)

Buggy submission (status: Runtime Error):
def solve(string):
    a, b, c, x = map(int, string.split())
    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if 500 * i + 100 * j + 50 * k == x:
                    ans += 1
    return str(ans)


if __name__ == "__main__":
    print(solve(input()))


Fixed submission:
def solve(string):
    a, b, c, x = map(int, string.split())
    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if 500 * i + 100 * j + 50 * k == x:
                    ans += 1
    return str(ans)


if __name__ == "__main__":
    n = 4
    print(solve("\n".join([input() for _ in range(n)])))
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<int> sa(n);
  vector<int> sb(n);
  sa[0] = 0;
  sb[0] = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sa[i + 1] = sa[i] + a;
  }
  rep(i, n) {
    int b;
    cin >> b;
    sb[i + 1] = sb[i] + b;
  }
  int ans = 0;
  rep(i, n) {
    int sum = sa[i + 1] - sa[0] + sb[n] - sb[i];
    if (ans < sum)
      ans = sum;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<int> sa(n + 1);
  vector<int> sb(n + 1);
  sa[0] = 0;
  sb[0] = 0;
  rep(i, n) {
    int a;
    cin >> a;
    sa[i + 1] = sa[i] + a;
  }
  rep(i, n) {
    int b;
    cin >> b;
    sb[i + 1] = sb[i] + b;
  }
  int ans = 0;
  rep(i, n) {
    int sum = sa[i + 1] - sa[0] + sb[n] - sb[i];
    if (ans < sum)
      ans = sum;
  }
  cout << ans << endl;
  return 0;
}
Problem p03449 (C++)

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

int m[3][101], dt[3][101];

int f(int i, int j) {
  if (i < 1 || j < 1)
    return 0;
  if (i == 1 && j == 1)
    return dt[1][1] = m[1][1];
  if (dt[i][j])
    return dt[i][j];
  return dt[i][j] = max(f(i - 1, j), f(i, j - 1)) + m[i][j];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++)
      scanf("%d", &m[i][j]);
  f(2, n);
  printf("%d", dt[n - 1][1]);
}


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

int m[3][101], dt[3][101];

int f(int i, int j) {
  if (i < 1 || j < 1)
    return 0;
  if (i == 1 && j == 1)
    return dt[1][1] = m[1][1];
  if (dt[i][j])
    return dt[i][j];
  return dt[i][j] = max(f(i - 1, j), f(i, j - 1)) + m[i][j];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++)
      scanf("%d", &m[i][j]);
  f(2, n);
  printf("%d", dt[2][n]);
}
Problem p03449 (C++)

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

int T(int i, int j, vector<vector<int>> a) {
  int t = a.at(i).at(j);
  int up = 0;
  int left = 0;
  if (i == 1 && j == 1)
    return a.at(i).at(j);
  if (i != 1) {
    up += T(i - 1, j, a);
  }
  if (j != 1) {
    left += T(i, j - 1, a);
  }

  t += max(up, left);

  return t;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> a(3, vector<int>(100));

  for (int i = 1; i <= N; i++) {
    cin >> a.at(1).at(i);
  }
  for (int i = 1; i <= N; i++) {
    cin >> a.at(2).at(i);
  }

  int t = T(2, N, a);

  cout << t << endl;
}


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

int T(int i, int j, vector<vector<int>> a) {
  int t = a.at(i).at(j);
  int up = 0;
  int left = 0;
  if (i == 1 && j == 1)
    return a.at(i).at(j);
  if (i != 1) {
    up += T(i - 1, j, a);
  }
  if (j != 1) {
    left += T(i, j - 1, a);
  }

  t += max(up, left);

  return t;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> a(3, vector<int>(101));

  for (int i = 1; i <= N; i++) {
    cin >> a.at(1).at(i);
  }
  for (int i = 1; i <= N; i++) {
    cin >> a.at(2).at(i);
  }

  int t = T(2, N, a);

  cout << t << endl;
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  for (int i = 0; i < n; i++)
    cin >> a[0][i];
  for (int i = 0; i < n; i++)
    cin >> a[1][i];
  for (int i = 0; i < n; i++) {
    a[0][i + 1] += a[0][i];
    a[1][n - 2 - i] += a[1][n - 1 - i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    ans = max(ans, a[0][i] + a[1][i]);
  cout << ans << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++)
      cin >> a[i][j];
  for (int i = 0; i < n - 1; i++) {
    a[0][i + 1] += a[0][i];
    a[1][n - 2 - i] += a[1][n - 1 - i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    ans = max(ans, a[0][i] + a[1][i]);
  cout << ans << '\n';
}
Problem p03449 (C++)

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

int main() {
  // your code goes here
  int array[1][100], n, highest = 0, sum = 0;
  cin >> n;
  for (int i = 0; i < 2; i++)
    for (int k = 0; k < n; k++) {
      cin >> array[i][k];
    }
  int right = n - 1;
  for (int l = 0; l < n; l++) {
    sum = 0;
    for (int a = 0; a <= l; a++) {
      sum += array[0][a];
    }
    for (int b = l; b < n; b++) {
      sum += array[1][b];
    }
    if (sum > highest)
      highest = sum;
  }
  cout << highest;
  return 0;
}

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

int main() {
  // your code goes here
  int array[2][101], n, highest = 0, sum = 0;
  cin >> n;
  for (int i = 0; i < 2; i++)
    for (int k = 0; k < n; k++) {
      cin >> array[i][k];
    }
  int right = n - 1;
  for (int l = 0; l < n; l++) {
    sum = 0;
    for (int a = 0; a <= l; a++) {
      sum += array[0][a];
    }
    for (int b = l; b < n; b++) {
      sum += array[1][b];
    }
    if (sum > highest)
      highest = sum;
  }
  cout << highest;
  return 0;
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
// cout << std::fixed << std::setprecision(15) << y << endl;

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

  ll A[2][N];
  rep(i, N * 2) { cin >> A[i / N][i]; }

  ll sum[2][N];
  sum[0][0] = A[0][0];
  sum[1][0] = sum[0][0] + A[1][0];
  REP(i, N - 1) {
    sum[0][i] = sum[0][i - 1] + A[0][i];
    sum[1][i] = max(sum[0][i], sum[1][i - 1]) + A[1][i];
  }

  cout << sum[1][N - 1] << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
// cout << std::fixed << std::setprecision(15) << y << endl;

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

  ll A[2][N];
  rep(i, N * 2) { cin >> A[i / N][i % N]; }

  ll sum[2][N];
  sum[0][0] = A[0][0];
  sum[1][0] = sum[0][0] + A[1][0];
  REP(i, N - 1) {
    sum[0][i] = sum[0][i - 1] + A[0][i];
    sum[1][i] = max(sum[0][i], sum[1][i - 1]) + A[1][i];
  }

  cout << sum[1][N - 1] << endl;

  return 0;
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[2][n + 1];
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++)
      a[i][j] = 0;
  }
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      int x;
      cin >> x;
      a[i][j] = max(a[i - 1][j], a[i][j - 1]) + x;
    }
  }
  cout << a[2][n];
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[3][n + 1];
  for (int i = 0; i <= 2; i++) {
    for (int j = 0; j <= n; j++)
      a[i][j] = 0;
  }
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      int x;
      cin >> x;
      a[i][j] = max(a[i - 1][j], a[i][j - 1]) + x;
    }
  }
  cout << a[2][n];
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#pragma warning(disable : 4996)
// FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define INF 1e18
#define NM 20005
#define MOD 1000000000
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define si(n) fscanf(in, "%d", &n)
#define sd(n) fscanf(in, "%lf", &n)
typedef long long int ll;
int a[2][105], d[2][105];
int main() {
  int n;
  si(n);
  FOR(i, 1, 2) FOR(j, 1, n) {
    si(a[i][j]);
    d[i][j] = max(d[i - 1][j], d[i][j - 1]) + a[i][j];
  }
  fprintf(out, "%d", d[2][n]);
  return 0;
}

Fixed submission:
#include <stdio.h>
#pragma warning(disable : 4996)
// FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
#define INF 1e18
#define NM 20005
#define MOD 1000000000
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define si(n) fscanf(in, "%d", &n)
#define sd(n) fscanf(in, "%lf", &n)
typedef long long int ll;
int a[3][105], d[3][105];
int main() {
  int n;
  si(n);
  FOR(i, 1, 2) FOR(j, 1, n) {
    si(a[i][j]);
    d[i][j] = max(d[i - 1][j], d[i][j - 1]) + a[i][j];
  }
  fprintf(out, "%d", d[2][n]);
  return 0;
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS int n;
  cin >> n;
  vector<vector<int>> v(2, vector<int>(n));

  REP(i, 2) REP(j, n) cin >> v[i][j];
  int cnt = accumulate(v[1].begin(), v[0].end(), 0) + v[0][0];
  int ans = cnt;
  REP(i, n - 1) {
    cnt = cnt + v[0][i + 1] - v[1][i];
    ans = max(cnt, ans);
  }

  cout << ans << '\n';

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS int n;
  cin >> n;
  vector<vector<int>> v(2, vector<int>(n));

  REP(i, 2) REP(j, n) cin >> v[i][j];
  int cnt = accumulate(v[1].begin(), v[1].end(), 0) + v[0][0];
  int ans = cnt;
  REP(i, n - 1) {
    cnt = cnt + v[0][i + 1] - v[1][i];
    ans = max(cnt, ans);
  }

  cout << ans << '\n';

  return 0;
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>

using namespace std;
int n, sz[5][105], f[5][105];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++)
      scanf("%d", &sz[i][j]);
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++)
      f[i][j] = max(f[i - 1][j], f[i][j - 1]) + sz[j][j];
  printf("%d", f[2][n]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>

using namespace std;
int n, sz[5][105], f[5][105];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++)
      scanf("%d", &sz[i][j]);
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= n; j++)
      f[i][j] = max(f[i - 1][j], f[i][j - 1]) + sz[i][j];
  printf("%d", f[2][n]);
  return 0;
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
#include <complex>
using namespace std;
int main() {
  int n, i, aa = 0, bb = 0, cnt, sum = 0;
  vector<int> a(n, 0), b(n, 0);
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n; i++) {
    cin >> b[i];
    bb += b[i];
  }
  for (i = 0; i < n; i++) {
    aa += a[i];
    if (i != 0)
      bb -= b[i - 1];
    cnt = aa + bb;
    if (cnt > sum)
      sum = cnt;
    cnt = 0;
  }
  cout << sum;
  system("pause");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
#include <complex>
using namespace std;
int main() {
  long long n, i, aa = 0, bb = 0, cnt, sum = 0;
  vector<long long> a(n, 0), b(n, 0);
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n; i++) {
    cin >> b[i];
    bb += b[i];
  }
  for (i = 0; i < n; i++) {
    aa += a[i];
    if (i != 0)
      bb -= b[i - 1];
    cnt = aa + bb;
    if (cnt > sum)
      sum = cnt;
    cnt = 0;
  }
  cout << sum;
  system("pause");
  return 0;
}
Problem p03449 (C++)

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

int main(void) {
  int n, a[2][105], sum = 0, max = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[1][i];
  for (int i = 1; i <= n; i++) {
    cin >> a[2][i];
    sum += a[2][i];
  }
  sum += a[1][1];
  if (max < sum)
    max = sum;
  for (int i = 1; i < n; i++) {
    sum += (a[1][i + 1] - a[2][i]);
    if (max < sum)
      max = sum;
  }
  cout << max << endl;
  return 0;
}


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

int main(void) {
  int n, a[5][205], sum = 0, max = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[1][i];
  for (int i = 1; i <= n; i++) {
    cin >> a[2][i];
    sum += a[2][i];
  }
  sum += a[1][1];
  if (max < sum)
    max = sum;
  for (int i = 1; i < n; i++) {
    sum += (a[1][i + 1] - a[2][i]);
    if (max < sum)
      max = sum;
  }
  cout << max << endl;
  return 0;
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<int> UE(N);
  vector<int> ST(N);
  vector<int> UES(N);
  vector<int> STS(N);
  vector<int> Ans(N);
  for (int i = 0; i < N; i++) {
    cin >> UE[i];
    if (i == 0) {
      UES[i] = UE[i];
    } else {
      UES[i] = UES[i - 1] + UE[i];
    }
  }
  for (int i = 0; i < N; i++) {
    cin >> ST[i];
    if (i == 0) {
      STS[i] = ST[i];
    } else {
      STS[i] = STS[i - 1] + ST[i];
    }
  }
  Ans[0] = UES[0] + STS[N - 1];
  for (int i = 1; i < N; i++) {
    Ans[i] = UES[i] + STS[N - 1] - STS[i - 1];
  }
  sort(Ans.begin(), Ans.end());
  cout << Ans[N - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> UE(N);
  vector<int> ST(N);
  vector<int> UES(N);
  vector<int> STS(N);
  vector<int> Ans(N);
  for (int i = 0; i < N; i++) {
    cin >> UE[i];
    if (i == 0) {
      UES[i] = UE[i];
    } else {
      UES[i] = UES[i - 1] + UE[i];
    }
  }
  for (int i = 0; i < N; i++) {
    cin >> ST[i];
    if (i == 0) {
      STS[i] = ST[i];
    } else {
      STS[i] = STS[i - 1] + ST[i];
    }
  }
  Ans[0] = UES[0] + STS[N - 1];
  for (int i = 1; i < N; i++) {
    Ans[i] = UES[i] + STS[N - 1] - STS[i - 1];
  }
  sort(Ans.begin(), Ans.end());
  cout << Ans[N - 1] << endl;
}
Problem p03449 (C++)

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

int main() {
  int n, i, j, s = 0, maxv = 0;
  cin >> n;

  int a[3][n + 1];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= 2; j++)
      cin >> a[i][j];

  for (i = 1; i <= n; i++) {
    s = 0;
    for (j = 1; j <= i; j++)
      s += a[1][j];
    for (j = i; j <= n; j++)
      s += a[2][j];

    if (s > maxv)
      maxv = s;
  }
  cout << maxv;

  return 0;
}

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

int main() {
  int n, i, j, s = 0, maxv = 0;
  cin >> n;

  int a[3][n + 1];
  for (i = 1; i <= 2; i++)
    for (j = 1; j <= n; j++)
      cin >> a[i][j];

  for (i = 1; i <= n; i++) {
    s = 0;
    for (j = 1; j <= i; j++)
      s += a[1][j];
    for (j = i; j <= n; j++)
      s += a[2][j];

    if (s > maxv)
      maxv = s;
  }
  cout << maxv;

  return 0;
}
Problem p03449 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a1(n), a2(n);
  for (int i = 0; i < n; i++)
    cin >> a1[i];
  for (int j = 0; j < n; j++)
    cin >> a2[j];

  vector<int> b1(n), b2(n);
  b1[0] = 0;
  b2[0] = 0;
  for (int k = 1; k < n + 1; k++) {
    b1[k] = a1[k - 1] + b1[k - 1];
    b2[k] = a2[k - 1] + b2[k - 1];
  }

  int ans = 0;
  for (int l = 1; l < n + 1; l++) {
    int t_candy = b1[l] + (b2[n] - b2[l - 1]);
    ans = max(ans, t_candy);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a1(n), a2(n);
  for (int i = 0; i < n; i++)
    cin >> a1[i];
  for (int j = 0; j < n; j++)
    cin >> a2[j];

  vector<int> b1(n + 1), b2(n + 1);
  b1[0] = 0;
  b2[0] = 0;
  for (int k = 1; k < n + 1; k++) {
    b1[k] = a1[k - 1] + b1[k - 1];
    b2[k] = a2[k - 1] + b2[k - 1];
  }

  int ans = 0;
  for (int l = 1; l < n + 1; l++) {
    int t_candy = b1[l] + (b2[n] - b2[l - 1]);
    ans = max(ans, t_candy);
  }
  cout << ans << endl;
}
Problem p03449 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int a1[n], a2[n];
  for (int i = 0; i < n; i++)
    cin >> a1[i];
  for (int i = 0; i < n; i++)
    cin >> a2[i];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int temp = 0;
    for (int j = 0; j <= i; j++)
      temp += a1[j];
    for (int j = i; i <= n - 1; j++)
      temp += a2[j];
    if (temp > sum)
      sum = temp;
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a1[n], a2[n];
  for (int i = 0; i < n; i++)
    cin >> a1[i];
  for (int i = 0; i < n; i++)
    cin >> a2[i];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int temp = 0;
    for (int j = 0; j <= i; j++)
      temp += a1[j];
    for (int j = i; j <= n - 1; j++)
      temp += a2[j];
    if (temp > sum)
      sum = temp;
  }
  cout << sum << endl;
  return 0;
}
Problem p03449 (C++)

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPD(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define FILLl(n, first_dimension_size, value)                                  \
  fill((ll *)n, (ll *)(n + first_dimension_size), value)
#define FILL(n, first_dimension_size, value)                                   \
  fill((int *)n, (int *)(n + first_dimension_size), value)
#define INF (1 << 30)
#define MOD 1000000007
// int dy[4] = {-1,0,0,1};
// int dx[4] = {0,1,-1,0};

int main() {

  int n;
  cin >> n;
  vector<int> up(n), down(n);
  up[0] = 0;
  REP(i, n + 1) {
    if (!i)
      continue;
    cin >> up[i];
    up[i] += up[i - 1];
  }
  down[0] = 0;
  REP(i, n + 1) {
    if (!i)
      continue;
    cin >> down[i];
    down[i] += down[i - 1];
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int sum = up[i] - up[0] + down[n] - down[i - 1];
    res = max(res, sum);
  }
  cout << res << endl;

  return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPD(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define FILLl(n, first_dimension_size, value)                                  \
  fill((ll *)n, (ll *)(n + first_dimension_size), value)
#define FILL(n, first_dimension_size, value)                                   \
  fill((int *)n, (int *)(n + first_dimension_size), value)
#define INF (1 << 30)
#define MOD 1000000007
// int dy[4] = {-1,0,0,1};
// int dx[4] = {0,1,-1,0};

int main() {

  int n;
  cin >> n;
  vector<int> up(n + 1), down(n + 1);
  up[0] = 0;
  REP(i, n + 1) {
    if (!i)
      continue;
    cin >> up[i];
    up[i] += up[i - 1];
  }
  down[0] = 0;
  REP(i, n + 1) {
    if (!i)
      continue;
    cin >> down[i];
    down[i] += down[i - 1];
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int sum = up[i] - up[0] + down[n] - down[i - 1];
    res = max(res, sum);
  }
  cout << res << endl;

  return 0;
}
Problem p03449 (C++)

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

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

  int a[2 + 2][5 + 2] = {0};
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> a[i][j];
    }
  }

  int answer = 0;

  // 横
  for (int j_down = 1; j_down <= N; j_down++) {

    int tmpSum = 0;

    // 1段目
    for (int k = 1; k <= j_down; k++) {
      tmpSum += a[1][k];
    }

    // 2 段目
    for (int k = j_down; k <= N; k++) {
      tmpSum += a[2][k];
    }

    answer = max(answer, tmpSum);
  }

  cout << answer << endl;

  return 0;
}

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

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

  int a[2 + 1][N + 1] = {0};
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> a[i][j];
    }
  }

  int answer = 0;

  // 横
  for (int j_down = 1; j_down <= N; j_down++) {

    int tmpSum = 0;

    // 1段目
    for (int k = 1; k <= j_down; k++) {
      tmpSum += a[1][k];
    }

    // 2 段目
    for (int k = j_down; k <= N; k++) {
      tmpSum += a[2][k];
    }

    answer = max(answer, tmpSum);
  }

  cout << answer << endl;

  return 0;
}
Problem p03449 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int one[n];
  int two[n];
  for (int i = 0; i < n; i++) {
    cin >> one[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> two[i];
  }

  int max = 0;
  for (int j = 0; j < n; j++) {
    int wa = 0;
    for (int k = 0; k <= j; k++) {
      wa += one[k];
    }
    for (int l = j; l < n; j++) {
      wa += two[l];
    }
    if (max < wa)
      max = wa;
  }

  cout << max << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int one[n];
  int two[n];
  for (int i = 0; i < n; i++) {
    cin >> one[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> two[i];
  }

  int max = 0;
  for (int j = 0; j < n; j++) {
    int wa = 0;
    for (int k = 0; k <= j; k++) {
      wa += one[k];
    }
    for (int l = j; l < n; l++) {
      wa += two[l];
    }
    if (max < wa)
      max = wa;
  }

  cout << max << "\n";
}
Problem p03449 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
const int mod = 100000000;
int a[2][222];
int sum[2][222];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++)
      scanf("%d", &a[i][j]);
  }
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(sum[1][i] + sum[2][n] - sum[2][i - 1], ans);
  }
  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
const int mod = 100000000;
int a[3][222];
int sum[3][222];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++)
      scanf("%d", &a[i][j]);
  }
  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= n; j++) {
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(sum[1][i] + sum[2][n] - sum[2][i - 1], ans);
  }
  printf("%d\n", ans);

  return 0;
}
Problem p03449 (C++)

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

int main() {
  int n;
  cin >> n;
  int a[2][n];

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

  int count = 0;
  int break_point = 1;
  while (break_point <= n) {
    int tmp_count = 0;
    int tmp = 1;
    for (int i = 1; i <= 2; i++) {
      for (int j = tmp; j <= n; j++) {
        tmp_count += a[i][j];
        if (break_point == j and i == 1) {
          tmp = j;
          break;
        }
      }
    }
    count = max(count, tmp_count);
    break_point++;
  }

  cout << count << endl;
}

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

int main() {
  int n;
  cin >> n;
  int a[3][n + 1];

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

  int count = 0;
  int break_point = 1;
  while (break_point <= n) {
    int tmp_count = 0;
    int tmp = 1;
    for (int i = 1; i <= 2; i++) {
      for (int j = tmp; j <= n; j++) {
        tmp_count += a[i][j];
        if (break_point == j and i == 1) {
          tmp = j;
          break;
        }
      }
    }
    count = max(count, tmp_count);
    break_point++;
  }

  cout << count << endl;
}
Problem p03450 (C++)

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

void dfs(ll s, vector<bool> &flg, vector<vector<pair<ll, ll>>> &g,
         vector<ll> &cost) {
  flg[s] = true;
  for (auto u : g[s]) {
    ll to = u.first;
    ll len = u.second;
    if (cost[to] == 1e18) {
      cost[to] = cost[s] + len;
    }
    if (cost[to] != cost[s] + len) {
      cout << "No" << endl;
      exit(0);
    }
    if (!flg[to]) {
      dfs(to, flg, g, cost);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<ll, ll>>> g(n);
  vector<bool> flg(n, false);
  vector<ll> cost(n, 1e18);
  rep(i, n) {
    ll l, r, d;
    cin >> l >> r >> d;
    --l, --r;
    g[l].push_back(make_pair(r, d));
    g[r].push_back(make_pair(l, -d));
  }
  rep(i, n) {
    if (!flg[i]) {
      cost[i] = 0LL;
      dfs(i, flg, g, cost);
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

void dfs(ll s, vector<bool> &flg, vector<vector<pair<ll, ll>>> &g,
         vector<ll> &cost) {
  flg[s] = true;
  for (auto u : g[s]) {
    ll to = u.first;
    ll len = u.second;
    if (cost[to] == 1e18) {
      cost[to] = cost[s] + len;
    }
    if (cost[to] != cost[s] + len) {
      cout << "No" << endl;
      exit(0);
    }
    if (!flg[to]) {
      dfs(to, flg, g, cost);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<ll, ll>>> g(n);
  vector<bool> flg(n, false);
  vector<ll> cost(n, 1e18);
  rep(i, m) {
    ll l, r, d;
    cin >> l >> r >> d;
    --l, --r;
    g[l].push_back(make_pair(r, d));
    g[r].push_back(make_pair(l, -d));
  }
  rep(i, n) {
    if (!flg[i]) {
      cost[i] = 0LL;
      dfs(i, flg, g, cost);
    }
  }
  cout << "Yes" << endl;
  return 0;
}