prithivMLmods/Coder-Stat huggingface dataset:
Problem p02748 (Python)

Buggy submission (status: Runtime Error):
A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans = 0
sav = 0
maxc = max(c)
ci = c.index(maxc)
disc = a[ci - 1] + b[ci - 1] - maxc
print(min(disc, min(a) + min(b)))


Fixed submission:
A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans, sav = float("inf"), 0
for j in range(M):
    sav = a[x[j] - 1] + b[y[j] - 1] - c[j]
    if ans > sav:
        ans = sav

print(min(ans, min(a) + min(b)))
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void solve() {
  int na, nb, m;
  cin >> na >> nb >> m;
  vector<int> a(na), b(nb);
  rep(i, na) cin >> a[i];
  rep(i, nb) cin >> b[i];
  vector<int> x(m), y(m), c(m);
  rep(i, m) cin >> x[i] >> y[i] >> c[i];
  rep(i, m) x[i]--, y[i]--;
  int ans = INF;
  rep(i, m) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
  rep(i, na) {
    rep(j, nb) { ans = min(ans, a[i] + b[j]); }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void solve() {
  int na, nb, m;
  cin >> na >> nb >> m;
  vector<int> a(na), b(nb);
  rep(i, na) cin >> a[i];
  rep(i, nb) cin >> b[i];
  vector<int> x(m), y(m), c(m);
  rep(i, m) cin >> x[i] >> y[i] >> c[i];
  rep(i, m) x[i]--, y[i]--;
  int ans = INF;
  rep(i, m) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
  sort(ALL(a));
  sort(ALL(b));
  ans = min(ans, a[0] + b[0]);
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int A, B, M;
  int ans = 1000000;
  int x, y, c;
  int a_min = 100000;
  int b_min = 100000;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  for (int i = 0; i < A; i++) {
    cin >> a[i];
    a_min = min(a[i], a_min);
  }
  for (int i = 0; i < A; i++) {
    cin >> b[i];
    b_min = min(b[i], b_min);
  }
  for (int i = 0; i < M; i++) {
    cin >> x >> y >> c;
    ans = min(ans, a[x - 1] + b[y - 1] - c);
  }
  ans = min(ans, a_min + b_min);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int A, B, M;
  int ans = 1000000;
  int x, y, c;
  int a_min = 100000;
  int b_min = 100000;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  for (int i = 0; i < A; i++) {
    cin >> a[i];
    a_min = min(a[i], a_min);
  }
  for (int i = 0; i < B; i++) {
    cin >> b[i];
    b_min = min(b[i], b_min);
  }
  for (int i = 0; i < M; i++) {
    cin >> x >> y >> c;
    ans = min(ans, a[x - 1] + b[y - 1] - c);
  }
  ans = min(ans, a_min + b_min);
  cout << ans << endl;
  return 0;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int lld;
int T;
int N, P;
int check[1000001];
int A, B, M;
vector<int> a;
vector<int> b;
int m1 = 1e9;
int m2 = 1e9;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B >> M;

  for (int i = 0; i < A; i++) {
    int t;
    cin >> t;
    m1 = min(t, m1);
    a.push_back(t);
  }
  for (int i = 0; i < B; i++) {
    int t;
    cin >> t;
    m2 = min(t, m2);
    b.push_back(t);
  }
  m1 = m1 + m2;
  for (int i = 0; i < M; i++) {
    int aa, bb, mm;
    cin >> aa >> bb >> mm;
    m1 = min(m1, a[aa - 1] + b[aa - 1] - mm);
  }
  cout << m1;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int lld;
int T;
int N, P;
int check[1000001];
int A, B, M;
vector<int> a;
vector<int> b;
int m1 = 1e9;
int m2 = 1e9;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B >> M;

  for (int i = 0; i < A; i++) {
    int t;
    cin >> t;
    m1 = min(t, m1);
    a.push_back(t);
  }
  for (int i = 0; i < B; i++) {
    int t;
    cin >> t;
    m2 = min(t, m2);
    b.push_back(t);
  }
  m1 = m1 + m2;
  for (int i = 0; i < M; i++) {
    int aa, bb, mm;
    cin >> aa >> bb >> mm;
    m1 = min(m1, a[aa - 1] + b[bb - 1] - mm);
  }
  cout << m1;
  return 0;
}
Problem p02748 (C++)

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

int main() {
  int A, B, m;
  cin >> A >> B >> m;
  vector<int> a(A);
  for (int i = 0; i < A; i++)
    cin >> a.at(i);
  vector<int> b(B);
  for (int i = 0; i < B; i++)
    cin >> b.at(i);

  int money = 200000;

  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    money = min(money, a.at(x - 1) + b.at(y - 1) - z);
  }
  for (int i = 0; i < A; i++) {
    for (int j = 0; j < B; j++) {
      money = min(money, a.at(i) + b.at(i));
    }
  }
  cout << money << endl;
}

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

int main() {
  int A, B, m;
  cin >> A >> B >> m;
  vector<int> a(A);
  for (int i = 0; i < A; i++)
    cin >> a.at(i);
  vector<int> b(B);
  for (int i = 0; i < B; i++)
    cin >> b.at(i);

  int money = 200000;

  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    money = min(money, a.at(x - 1) + b.at(y - 1) - z);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  cout << min(money, a.at(0) + b.at(0)) << endl;
}
Problem p02748 (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++)
using ll = long long;
template <class T> using vt = vector<T>;
using vvi = vector<vector<int>>;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vt<int> a(A), b(B), x(M), y(M), c(M);

  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  rep(i, M) cin >> x[i] >> y[i] >> c[i];

  int ans = 1000000;
  rep(i, A) {
    int minm = 0;
    rep(j, B) {
      minm = a[i] + b[j];
      ans = min(ans, minm);
    }
  }

  rep(i, M) { ans = min(ans, (a[x[i] - 1] + b[y[i] - 1] - c[i])); }

  cout << ans;
  return 0;
}


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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vt<int> a(A), b(B), x(M), y(M), c(M);

  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  rep(i, M) cin >> x[i] >> y[i] >> c[i];

  int min_a = *min_element(a.begin(), a.end());
  int min_b = *min_element(b.begin(), b.end());
  int ans = min_a + min_b;

  rep(i, M) { ans = min(ans, (a[x[i] - 1] + b[y[i] - 1] - c[i])); }

  cout << ans;
  return 0;
}
Problem p02748 (C++)

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;

  int a[A], b[B];
  rep(i, A) { cin >> a[i]; }
  rep(i, B) { cin >> b[i]; }

  int x[M], y[M], c[M];
  rep(i, M) { cin >> x[i] >> y[i] >> c[i]; }

  int ans = 100000000;
  rep(i, M) {
    int tmp = a[x[i] - 1] + b[y[i] - 1] - c[i];
    ans = min(ans, tmp);
  }
  sort(a, a + M);
  sort(b, b + M);
  int q = a[0] + b[0];
  ans = min(ans, q);
  cout << ans << endl;
  return 0;
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;

  int a[A], b[B];
  rep(i, A) { cin >> a[i]; }
  rep(i, B) { cin >> b[i]; }

  int x[M], y[M], c[M];
  rep(i, M) { cin >> x[i] >> y[i] >> c[i]; }

  int ans = 100000000;
  rep(i, M) {
    int tmp = a[x[i] - 1] + b[y[i] - 1] - c[i];
    ans = min(ans, tmp);
  }
  int mina = 1000000;
  int minb = 1000000;
  rep(i, A) {
    if (a[i] < mina)
      mina = a[i];
  }
  rep(i, B) {
    if (b[i] < minb)
      minb = b[i];
  }
  int q = mina + minb;
  ans = min(ans, q);
  cout << ans << endl;
  return 0;
}
Problem p02748 (C++)

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

int main() {
  int64_t a, b, m;
  cin >> a >> b >> m;
  vector<int64_t> av(a), bv(b);
  rep(i, a) { cin >> av[i]; }
  rep(i, b) { cin >> bv[i]; }
  int64_t minp = 100000000000000;
  rep(i, a) {
    rep(j, b) {
      minp = min(minp, av[i] + bv[j]);
      // cout << av[i]+bv[j] << endl;
    }
  }
  rep(i, m) {
    int64_t q, w, e;
    cin >> q >> w >> e;
    minp = min(minp, av[q - 1] + bv[w - 1] - e);
  }
  cout << minp << endl;
}


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

int main() {
  int64_t a, b, m;
  cin >> a >> b >> m;
  vector<int64_t> av(a), bv(b);
  rep(i, a) { cin >> av[i]; }
  rep(i, b) { cin >> bv[i]; }
  int64_t minp = 100000000000000;
  minp = *(min_element(av.begin(), av.end())) +
         *(min_element(bv.begin(), bv.end()));
  rep(i, m) {
    int64_t q, w, e;
    cin >> q >> w >> e;
    minp = min(minp, av[q - 1] + bv[w - 1] - e);
  }
  cout << minp << endl;
}
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <climits>
using namespace std;
int main() {
  long long int n, m, i, k, l, p = 0, j, sum, x = 1;
  p = INT_MAX;
  int t = INT_MAX;
  cin >> n >> m >> k;
  int a[n], b[m], c[k], d[k], e[k];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (i = 0; i < k; i++) {
    cin >> c[i] >> d[i] >> e[i];
    l = a[c[i] - 1] + b[d[i] - 1] - e[i];
    if (p > l) {
      p = l;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      sum = a[i] + b[j];
      if (sum < t) {
        t = sum;
      }
    }
  }
  if (p > t) {
    cout << t;
  } else {
    cout << p;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <climits>
using namespace std;
int main() {
  long long int n, m, i, k, l, p = 0, j, sum, x = 1;
  p = INT_MAX;
  int t = INT_MAX;
  cin >> n >> m >> k;
  int a[n], b[m], c[k], d[k], e[k];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (i = 0; i < k; i++) {
    cin >> c[i] >> d[i] >> e[i];
    l = a[c[i] - 1] + b[d[i] - 1] - e[i];
    if (p > l) {
      p = l;
    }
  }
  sort(a, a + n);
  sort(b, b + n);
  t = a[0] + b[0];
  if (p > t) {
    cout << t;
  } else {
    cout << p;
  }
}
Problem p02748 (C++)

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  int s = 200000, t = 200000;
  vector<int> p(A + 1), q(B + 1);
  for (int i = 1; i <= A; i++) {
    cin >> p[i];
    s = min(s, p[i]);
  }
  for (int i = 1; i <= B; i++) {
    cin >> q.at(i);
    t = min(t, q[i]);
  }
  int c = 200000;
  int x, y, r;
  for (int i = 1; i <= M; i++) {
    cin >> x >> y >> r;
    c = min(c, p[x] + q[y] - r);
  }
  for (int i = 1; i <= A; i++) {
    for (int j = 1; j <= B; j++) {
      c = min(c, p[i] + q[j]);
    }
  }
  cout << min(c, s + t);
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  int s = 200000, t = 200000;
  vector<int> p(A + 1), q(B + 1);
  for (int i = 1; i <= A; i++) {
    cin >> p[i];
    s = min(s, p[i]);
  }
  for (int i = 1; i <= B; i++) {
    cin >> q.at(i);
    t = min(t, q[i]);
  }
  int c = 200000;
  int x, y, r;
  for (int i = 1; i <= M; i++) {
    cin >> x >> y >> r;
    c = min(c, p[x] + q[y] - r);
  }
  cout << min(c, s + t);
}
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

  int A, B, M;
  cin >> A >> B >> M;
  vi a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  vi x(M), y(M), c(M);
  rep(i, M) cin >> x[i] >> y[i] >> c[i];

  int minval = a[0] + b[0];
  rep(i, A) {
    rep(j, B) {
      int max_dis = 0;
      rep(k, M) {
        if (x[k] - 1 == i && y[k] - 1 == j) {
          max_dis = max(max_dis, c[k]);
        }
      }
      minval = min(minval, a[i] + b[j] - max_dis);
    }
  }

  cout << minval << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

  int A, B, M;
  cin >> A >> B >> M;
  vi a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  vi x(M), y(M), c(M);
  rep(i, M) cin >> x[i] >> y[i] >> c[i];

  int min_a = a[0], min_b = b[0];
  repm(i, 1, A) { min_a = min(min_a, a[i]); }
  repm(i, 1, A) { min_b = min(min_b, b[i]); }
  int minval = min_a + min_b;
  rep(i, M) { minval = min(minval, a[x[i] - 1] + b[y[i] - 1] - c[i]); }

  // int minval = a[0] + b[0];
  // rep(i, A)
  // {
  //     rep(j, B)
  //     {
  //         int max_dis = 0;
  //         rep(k, M)
  //         {
  //             if (x[k] - 1 == i && y[k] - 1 == j)
  //             {
  //                 max_dis = max(max_dis, c[k]);
  //             }
  //         }
  //         minval = min(minval, a[i] + b[j] - max_dis);
  //     }
  // }

  cout << minval << endl;

  return 0;
}
Problem p02748 (C++)

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

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int a, b, m;
vector<int> r, d;
vector<int> x, y, c;

int main() {
  vector<int> hoge(LLONG_MAX);
  cin >> a >> b >> m;
  r.resize(a), d.resize(b);
  for (int i = 0; i < a; i++) {
    cin >> r[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> d[i];
  }
  x.resize(m);
  y.resize(m);
  c.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--, y[i]--;
  }
  int mr = *min_element(r.begin(), r.end());
  int md = *min_element(d.begin(), d.end());
  int ans = INT_MAX;
  chmin(ans, mr + md);
  for (int i = 0; i < m; i++) {
    int cand = r[x[i]] + d[y[i]] - c[i];
    chmin(ans, cand);
  }
  cout << ans << endl;
}


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

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int a, b, m;
vector<int> r, d;
vector<int> x, y, c;

int main() {
  vector<int> hoge(100000000);
  cin >> a >> b >> m;
  r.resize(a), d.resize(b);
  for (int i = 0; i < a; i++) {
    cin >> r[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> d[i];
  }
  x.resize(m);
  y.resize(m);
  c.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--, y[i]--;
  }
  int mr = *min_element(r.begin(), r.end());
  int md = *min_element(d.begin(), d.end());
  int ans = INT_MAX;
  chmin(ans, mr + md);
  for (int i = 0; i < m; i++) {
    int cand = r[x[i]] + d[y[i]] - c[i];
    chmin(ans, cand);
  }
  cout << ans << endl;
}
Problem p02748 (C++)

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  for (int i = 0; i < A; i++)
    cin >> a.at(i);
  for (int i = 0; i < B; i++)
    cin >> b.at(i);

  int minA = *min_element(a.begin(), a.end());
  int minB = *min_element(b.begin(), b.end());
  int res = minA + minB;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    res = min(res, a.at(x) + a.at(y) - c);
  }
  cout << res << endl;
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  for (int i = 0; i < A; i++)
    cin >> a.at(i);
  for (int i = 0; i < B; i++)
    cin >> b.at(i);

  int minA = *min_element(a.begin(), a.end());
  int minB = *min_element(b.begin(), b.end());
  int res = minA + minB;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    res = min(res, a.at(x) + b.at(y) - c);
  }
  cout << res << endl;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define RREP(i, n) for (int(i) = ((int)(n)-1); (i) >= 0; i--)
#define RFOR(i, a, b) for (int(i) = ((int)(b)-1); (i) >= (int)a; i--)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (int)x.size()
#define SP(x) setprecision((int)x)

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     // 最小公倍数

//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }

//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> r(a);
  vector<int> d(b);
  REP(i, a) { cin >> r[i]; }
  REP(i, b) { cin >> d[i]; }
  int ans = INF;
  REP(i, m) {
    int x, y, c;
    int sum = 0;
    x--;
    y--;
    sum = r[x] + d[y] - c;
    ans = min(sum, ans);
  }
  sort(ALL(r));
  sort(ALL(d));
  ans = min(ans, r[0] + d[0]);
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define RREP(i, n) for (int(i) = ((int)(n)-1); (i) >= 0; i--)
#define RFOR(i, a, b) for (int(i) = ((int)(b)-1); (i) >= (int)a; i--)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (int)x.size()
#define SP(x) setprecision((int)x)

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     // 最小公倍数

//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }

//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> r(a);
  vector<int> d(b);
  REP(i, a) { cin >> r[i]; }
  REP(i, b) { cin >> d[i]; }
  int ans = INF;
  REP(i, m) {
    int x, y, c;
    cin >> x >> y >> c;
    int sum = 0;
    x--;
    y--;
    sum = r[x] + d[y] - c;
    ans = min(sum, ans);
  }
  sort(ALL(r));
  sort(ALL(d));
  ans = min(ans, r[0] + d[0]);
  cout << ans << endl;

  return 0;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int A, B, M, a[100], b[100], i, j, m[100], x[100], y[100];
  cin >> A >> B >> M;
  for (i = 1; i <= A; i++)
    cin >> a[i];
  for (i = 1; i <= B; i++)
    cin >> b[i];
  for (i = 1; i <= M; i++) {
    cin >> x[i] >> y[i] >> m[i];
  }
  int mina = a[1], minb = b[1], s, c;
  for (i = 1; i <= A; i++) {
    if (a[i] < mina)
      mina = a[i];
  }
  for (i = 1; i <= B; i++) {
    if (b[i] < minb)
      minb = b[i];
  }
  s = mina + minb;
  for (i = 1; i <= M; i++) {
    int h = a[x[i]] + b[y[i]] - m[i];
    if (s > h)
      s = h;
  }
  cout << s;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int A, B, M, a[100005], b[100005], i, j, m[100005], x[100005], y[100005];
  cin >> A >> B >> M;
  for (i = 1; i <= A; i++)
    cin >> a[i];
  for (i = 1; i <= B; i++)
    cin >> b[i];
  for (i = 1; i <= M; i++) {
    cin >> x[i] >> y[i] >> m[i];
  }
  int mina = a[1], minb = b[1], s, c;
  for (i = 1; i <= A; i++) {
    if (a[i] < mina)
      mina = a[i];
  }
  for (i = 1; i <= B; i++) {
    if (b[i] < minb)
      minb = b[i];
  }
  s = mina + minb;
  for (i = 1; i <= M; i++) {
    int h = a[x[i]] + b[y[i]] - m[i];
    if (s > h)
      s = h;
  }
  cout << s;
}
Problem p02748 (C++)

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

int ha[10005] = {0};
int hb[10005] = {0};

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  ha[0] = 100000000;
  hb[0] = 100000000;
  for (int i = 1; i <= A; i++) {
    cin >> ha[i];
    if (ha[i] < ha[0])
      ha[0] = ha[i];
  }
  for (int i = 1; i <= B; i++) {
    cin >> hb[i];
    if (hb[i] < hb[0])
      hb[0] = hb[i];
  }

  int ans = ha[0] + hb[0];
  for (int i = 1; i <= M; i++) {

    int x, y, c;
    cin >> x >> y >> c;
    if (ha[x] + hb[y] - c < ans)
      ans = ha[x] + hb[y] - c;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int ha[100005] = {0};
int hb[100005] = {0};

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  ha[0] = 100000000;
  hb[0] = 100000000;
  for (int i = 1; i <= A; i++) {
    cin >> ha[i];
    if (ha[i] < ha[0])
      ha[0] = ha[i];
  }
  for (int i = 1; i <= B; i++) {
    cin >> hb[i];
    if (hb[i] < hb[0])
      hb[0] = hb[i];
  }

  int ans = ha[0] + hb[0];
  for (int i = 1; i <= M; i++) {

    int x, y, c;
    cin >> x >> y >> c;
    if (ha[x] + hb[y] - c < ans)
      ans = ha[x] + hb[y] - c;
  }
  cout << ans << endl;
}
Problem p02748 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long LL;
using namespace std;

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> A(a);
  int mia = 1001001;
  rep(i, a) {
    cin >> A[i];
    mia = min(A[i], mia);
  }
  vector<int> B(b);
  int mib = 1001001;
  rep(i, a) {
    cin >> B[i];
    mib = min(B[i], mib);
  }
  vector<vector<int>> M(m, vector<int>(3));
  rep(i, m) {
    rep(j, 3) { cin >> M[i][j]; }
  }

  int v = 0;
  int ans = mia + mib;
  rep(i, m) {
    v = A[M[i][0] - 1] + B[M[i][1] - 1] - M[i][2];
    ans = min(v, ans);
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long LL;
using namespace std;

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> A(a);
  int mia = 1001001;
  rep(i, a) {
    cin >> A[i];
    mia = min(A[i], mia);
  }
  vector<int> B(b);
  int mib = 1001001;
  rep(i, b) {
    cin >> B[i];
    mib = min(B[i], mib);
  }
  vector<vector<int>> M(m, vector<int>(3));
  rep(i, m) {
    rep(j, 3) { cin >> M[i][j]; }
  }

  int v = 0;
  int ans = mia + mib;
  rep(i, m) {
    v = A[M[i][0] - 1] + B[M[i][1] - 1] - M[i][2];
    ans = min(v, ans);
  }
  cout << ans << endl;

  return 0;
}
Problem p02748 (C++)

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#define int long long int
  int a, b, m, ans = INT_MAX;
  cin >> a >> b >> m;
  int p[a], q[b];
  int x, y, c;
  for (int i = 0; i < a; i++)
    cin >> p[i];
  for (int i = 0; i < b; i++)
    cin >> q[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> c;
    ans = min(p[x - 1] + q[y - 1] - c, ans);
  }
  int ans1 = INT_MAX;

  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      ans1 = min(ans1, p[i] + q[j]);
    }
  }
  cout << min(ans1, ans) << endl;

  return 0;
}


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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#define int long long int
  int a, b, m, ans = INT_MAX;
  cin >> a >> b >> m;
  int p[a], q[b];
  int x, y, c;
  for (int i = 0; i < a; i++)
    cin >> p[i];
  for (int i = 0; i < b; i++)
    cin >> q[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> c;
    ans = min(p[x - 1] + q[y - 1] - c, ans);
  }
  int ans1 = INT_MAX;

  sort(p, p + a);
  sort(q, q + a);

  cout << min(p[0] + q[0], ans) << endl;

  return 0;
}
Problem p02748 (C++)

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  int ans = *min_element(a.begin(), b.end()) + *min_element(b.begin(), b.end());
  rep(i, M) {
    int x1, y1, c1;
    cin >> x1 >> y1 >> c1;
    x1--;
    y1--;
    ans = min(ans, a[x1] + b[y1] - c1);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
  rep(i, M) {
    int x1, y1, c1;
    cin >> x1 >> y1 >> c1;
    x1--;
    y1--;
    ans = min(ans, a[x1] + b[y1] - c1);
  }
  cout << ans << endl;
  return 0;
}
Problem p02748 (C++)

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;

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

  vector<int> b(B);
  for (int j = 0; j < B; j++) {
    cin >> b.at(j);
  }

  vector<int> x(M), y(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
  }
  int answer = a.at(x.at(0)) + b.at(y.at(0)) - c.at(0);
  for (int i = 0; i < M; i++) {
    if (answer > a.at(x.at(i)) + b.at(y.at(i)) - c.at(i)) {
      answer = a.at(x.at(i)) + b.at(y.at(i)) - c.at(i);
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (answer < a.at(0) + b.at(0)) {
    cout << answer << endl;
  } else {
    cout << a.at(0) + b.at(0) << endl;
  }
}


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

int main() {
  int A, B, M;
  cin >> A >> B >> M;

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

  vector<int> b(B);
  for (int j = 0; j < B; j++) {
    cin >> b.at(j);
  }

  vector<int> x(M), y(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
    --x.at(i);
    --y.at(i);
  }
  int answer = a.at(x.at(0)) + b.at(y.at(0)) - c.at(0);
  for (int i = 0; i < M; i++) {
    if (answer > a.at(x.at(i)) + b.at(y.at(i)) - c.at(i)) {
      answer = a.at(x.at(i)) + b.at(y.at(i)) - c.at(i);
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (answer < a.at(0) + b.at(0)) {
    cout << answer << endl;
  } else {
    cout << a.at(0) + b.at(0) << endl;
  }
}
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const ll INF = ll(1e18) + 1;
const double PI = 3.14159265358979323846;

int main() {
  int A, B, M, a[101000] = {}, b[101000] = {}, x[101000] = {}, y[101000] = {},
               c[100100] = {};
  cin >> A >> B >> M;
  rep(i, A) cin >> a[i + 1];
  rep(i, B) cin >> b[i + 1];
  rep(i, M) cin >> x[i] >> y[i] >> c[i];

  int ans = 1e+9;
  rep(i, M) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
  rep(i, A) {
    for (int j = i + 1; j < B; j++) {
      ans = min(ans, a[i + 1] + b[i + 1]);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const ll INF = ll(1e18) + 1;
const double PI = 3.14159265358979323846;

int main() {
  int A, B, M, a[101000] = {}, b[101000] = {}, x[101000] = {}, y[101000] = {},
               c[100100] = {};
  cin >> A >> B >> M;
  rep(i, A) cin >> a[i + 1];
  rep(i, B) cin >> b[i + 1];
  rep(i, M) cin >> x[i] >> y[i] >> c[i];

  int ans = 1e+9;
  rep(i, M) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
  sort(a + 1, a + A + 1);
  sort(b + 1, b + B + 1);
  ans = min(ans, a[1] + b[1]);
  cout << ans << endl;
}
Problem p02748 (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; ++i)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;

int main() {
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  vector<int> b(B);
  rep(i, A) { cin >> a.at(i); }
  rep(i, B) { cin >> b.at(i); }

  vector<vector<int>> c(M, vector<int>(3));
  rep(i, M) { cin >> c.at(i).at(0) >> c.at(i).at(1) >> c.at(i).at(2); }

  int minA = *std::min_element(a.begin(), a.end());
  int minB = *std::min_element(b.begin(), b.end());

  vector<int> off(M + 1);
  rep(i, M) {
    off.at(i) = a.at(c.at(i).at(0)) + b.at(c.at(i).at(1)) - c.at(i).at(2);
  }
  off.at(M) = minA + minB;

  int min = *std::min_element(off.begin(), off.end());
  cout << min << 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; ++i)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;

int main() {
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  vector<int> b(B);
  rep(i, A) { cin >> a.at(i); }
  rep(i, B) { cin >> b.at(i); }

  vector<vector<int>> c(M, vector<int>(3));
  rep(i, M) { cin >> c.at(i).at(0) >> c.at(i).at(1) >> c.at(i).at(2); }

  int minA = *std::min_element(a.begin(), a.end());
  int minB = *std::min_element(b.begin(), b.end());

  vector<int> off(M + 1);
  rep(i, M) {
    off.at(i) =
        a.at(c.at(i).at(0) - 1) + b.at(c.at(i).at(1) - 1) - c.at(i).at(2);
  }
  off.at(M) = minA + minB;

  int min = *std::min_element(off.begin(), off.end());
  cout << min << endl;
}
Problem p02748 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli mod = 998244353;
const lli inf = 1e18;

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> aa(m), bb(m);
  for (int i = 0; i < a; i++) {
    cin >> aa[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> bb[i];
  }
  int ans =
      *min_element(aa.begin(), aa.end()) + *min_element(bb.begin(), bb.end());
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, aa[x] + bb[y] - c);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli mod = 998244353;
const lli inf = 1e18;

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> aa(a), bb(b);
  for (int i = 0; i < a; i++) {
    cin >> aa[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> bb[i];
  }
  int ans =
      *min_element(aa.begin(), aa.end()) + *min_element(bb.begin(), bb.end());
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, aa[x] + bb[y] - c);
  }
  cout << ans << endl;
  return 0;
}
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A, 0);
  vector<int> b(B, 0);
  int tmp_a = 10e9 + 1, tmp_b = 10e9 + 1;
  for (int i = 0; i < A; ++i) {
    cin >> a[i];
    tmp_a = min(tmp_a, a[i]);
  }
  for (int i = 0; i < B; ++i) {
    cin >> b[i];
    tmp_b = min(tmp_b, b[i]);
  }
  int ans = tmp_a + tmp_b;
  for (int i = 0; i < A; ++i) {
    for (int j = 0; j < B; ++j) {
      ans = min(ans, a[i] + b[j]);
    }
  }
  for (int i = 0; i < M; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    if (ans > (a[x - 1] + b[y - 1]) - z)
      ans = (a[x - 1] + b[y - 1]) - z;
  }
  printf("%d\n", ans);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A, 0);
  vector<int> b(B, 0);
  int tmp_a = 10e9 + 1, tmp_b = 10e9 + 1;
  for (int i = 0; i < A; ++i) {
    cin >> a[i];
    tmp_a = min(tmp_a, a[i]);
  }
  for (int i = 0; i < B; ++i) {
    cin >> b[i];
    tmp_b = min(tmp_b, b[i]);
  }
  int ans = tmp_a + tmp_b;
  for (int i = 0; i < M; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    if (ans > (a[x - 1] + b[y - 1]) - z)
      ans = (a[x - 1] + b[y - 1]) - z;
  }
  printf("%d\n", ans);
}
Problem p02748 (C++)

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

int main() {
  int A, B, M, Min_a = 100000, Min_b = 100000, ans;
  cin >> A >> B >> M;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  for (int i = 0; i < A; i++) {
    cin >> a.at(i);
    if (Min_a > a.at(i)) {
      Min_a = a.at(i);
    }
  }
  for (int i = 0; i < B; i++) {
    cin >> b.at(i);
    if (Min_b > b.at(i)) {
      Min_b = b.at(i);
    }
  }

  ans = Min_a + Min_b;

  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
    if (a.at(x.at(i)) + b.at(y.at(i)) - c.at(i) < ans) {
      ans = a.at(x.at(i)) + b.at(y.at(i)) - c.at(i);
    }
  }
  cout << ans << endl;
}


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

int main() {
  int A, B, M, Min_a = 100000, Min_b = 100000, ans;
  cin >> A >> B >> M;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  for (int i = 0; i < A; i++) {
    cin >> a.at(i);
    if (Min_a > a.at(i)) {
      Min_a = a.at(i);
    }
  }
  for (int i = 0; i < B; i++) {
    cin >> b.at(i);
    if (Min_b > b.at(i)) {
      Min_b = b.at(i);
    }
  }

  ans = Min_a + Min_b;

  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
    if (a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i) < ans) {
      ans = a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i);
    }
  }
  cout << ans << endl;
}
Problem p02748 (C++)

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

int main() {
  int an, bn, mn;
  int min;
  int min_a = 99999;
  int min_b = 99999;
  int a[10000];
  int b[10000];
  for (int i = 0; i < 10000; i++)
    a[i] = b[i] = 0;
  std::cin >> an >> bn >> mn;
  for (int i = 0; i < an; i++) {
    std::cin >> a[i];
    if (min_a > a[i])
      min_a = a[i];
  }

  for (int i = 0; i < bn; i++) {
    std::cin >> b[i];
    if (min_b > b[i])
      min_b = b[i];
  }
  min = min_a + min_b;

  for (int i = 0; i < mn; ++i) {
    int xi, yi, c;
    std::cin >> xi >> yi >> c;
    int temp = a[xi - 1] + b[yi - 1] - c;
    if (min > temp)
      min = temp;
  }
  std::cout << min << std::endl;
}

Fixed submission:
#include <iostream>

int main() {
  int an, bn, mn;
  int min;
  int min_a = 999999;
  int min_b = 999999;
  int a[100000];
  int b[100000];
  for (int i = 0; i < 100000; i++)
    a[i] = b[i] = 0;
  std::cin >> an >> bn >> mn;
  for (int i = 0; i < an; i++) {
    std::cin >> a[i];
    if (min_a > a[i])
      min_a = a[i];
  }

  for (int i = 0; i < bn; i++) {
    std::cin >> b[i];
    if (min_b > b[i])
      min_b = b[i];
  }
  min = min_a + min_b;

  for (int i = 0; i < mn; ++i) {
    int xi, yi, c;
    std::cin >> xi >> yi >> c;
    int temp = a[xi - 1] + b[yi - 1] - c;
    if (min > temp)
      min = temp;
  }
  std::cout << min << std::endl;
}
Problem p02748 (C++)

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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> A(a);
  vector<int> B(b);
  vector<int> x(m);
  vector<int> y(m);
  vector<int> c(m);

  rep(i, a) { cin >> A[i]; }
  rep(i, b) { cin >> B[i]; }
  rep(i, m) { cin >> x[i] >> y[i] >> c[i]; }

  int ans = 1000000;

  rep(i, m) { ans = min(ans, A[x[i] - 1] + B[y[i] - 1] - c[i]); }

  if (a > b) {
    rep(i, a) {
      rep(j, b) { ans = min(ans, A[i] + B[j]); }
    }
  } else {
    rep(i, b) {
      rep(j, a) { ans = min(ans, A[j] + B[i]); }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> A(a);
  vector<int> B(b);
  vector<int> x(m);
  vector<int> y(m);
  vector<int> c(m);

  rep(i, a) { cin >> A[i]; }
  rep(i, b) { cin >> B[i]; }
  rep(i, m) { cin >> x[i] >> y[i] >> c[i]; }

  int ans = 1000000;

  rep(i, m) { ans = min(ans, A[x[i] - 1] + B[y[i] - 1] - c[i]); }

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  ans = min(ans, A[0] + B[0]);

  cout << ans << endl;

  return 0;
}
Problem p02748 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> aa(A), bb(B);
  for (int i = 0; i < A; i++) {
    cin >> aa.at(i);
  }
  for (int i = 0; i < B; i++) {
    cin >> bb.at(i);
  }
  vector<int> x(M), y(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
    x.at(i)--;
    y.at(i)--;
  }

  int result = aa.at(0) + bb.at(0);
  for (int i = 0; i < M; i++) {
    int sum = aa.at(x.at(i)) + bb.at(y.at(i)) - c.at(i);
    if (result > sum)
      result = sum;
  }
  for (int i = 0; i < A; i++) {
    for (int j = 0; j < B; j++) {
      int sum = aa.at(i) + bb.at(j);
      if (result > sum)
        result = sum;
    }
  }
  cout << result << endl;
}


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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> aa(A), bb(B);
  for (int i = 0; i < A; i++) {
    cin >> aa.at(i);
  }
  for (int i = 0; i < B; i++) {
    cin >> bb.at(i);
  }
  vector<int> x(M), y(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
    x.at(i)--;
    y.at(i)--;
  }

  int result = aa.at(0) + bb.at(0);
  for (int i = 0; i < M; i++) {
    int sum = aa.at(x.at(i)) + bb.at(y.at(i)) - c.at(i);
    if (result > sum)
      result = sum;
  }

  sort(ALL(aa));
  sort(ALL(bb));
  if (result > aa.at(0) + bb.at(0))
    result = aa.at(0) + bb.at(0);

  cout << result << endl;
}
Problem p02748 (C++)

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

int main() {
  long a, b, m, temp = LONG_MAX, ans = LONG_MAX;
  cin >> a >> b >> m;
  vector<long> va(a), vb(b);
  rep(i, a) {
    cin >> va.at(i);
    if (ans > va.at(i))
      ans = va.at(i);
  }
  rep(i, b) {
    cin >> vb.at(i);
    if (temp > va.at(i))
      temp = va.at(i);
  }
  ans += temp;
  rep(i, m) {
    long x, y, c;
    cin >> x >> y >> c;
    ans = min(ans, va.at(x - 1) + vb.at(y - 1) - c);
  }
  cout << ans << endl;
}

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

int main() {
  long a, b, m, temp = LONG_MAX, ans = LONG_MAX;
  cin >> a >> b >> m;
  vector<long> va(a), vb(b);
  rep(i, a) {
    cin >> va.at(i);
    if (ans > va.at(i))
      ans = va.at(i);
  }
  rep(i, b) {
    cin >> vb.at(i);
    if (temp > vb.at(i))
      temp = vb.at(i);
  }
  ans += temp;
  rep(i, m) {
    long x, y, c;
    cin >> x >> y >> c;
    ans = min(ans, va.at(x - 1) + vb.at(y - 1) - c);
  }
  cout << ans << endl;
}
Problem p02748 (C++)

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  vector<int> b(B);
  for (int i = 0; i < B; i++)
    cin >> b[i];
  int minA = *min_element(a.begin(), a.end());
  int minB = *min_element(b.begin(), b.end());
  int ans = minA + minB;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> x;
    x--;
    y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << endl;
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  vector<int> b(B);
  for (int i = 0; i < B; i++)
    cin >> b[i];
  int minA = *min_element(a.begin(), a.end());
  int minB = *min_element(b.begin(), b.end());
  int ans = minA + minB;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << endl;
}
Problem p02748 (C++)

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

int main() {
  int A, B, M;
  vector<int> a(A);
  vector<int> b(B);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, a[x] + b[y] - c);
  }
  cout << ans << endl;
  return 0;
}
Problem p02748 (C++)

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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> cost_a(a), cost_b(b);
  for (int i = 0; i < a; i++)
    cin >> cost_a.at(i);
  for (int i = 0; i < b; i++)
    cin >> cost_b.at(i);
  int ans = *min_element(cost_a.begin(), cost_a.end()) +
            *min_element(cost_b.begin(), cost_b.end());
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    int n = cost_a.at(x) + cost_b.at(x) - c;
    ans = min(ans, n);
  }
  cout << ans << endl;
}


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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> cost_a(a), cost_b(b);
  for (int i = 0; i < a; i++)
    cin >> cost_a.at(i);
  for (int i = 0; i < b; i++)
    cin >> cost_b.at(i);
  int ans = *min_element(cost_a.begin(), cost_a.end()) +
            *min_element(cost_b.begin(), cost_b.end());
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    int n = cost_a.at(x) + cost_b.at(y) - c;
    ans = min(ans, n);
  }
  cout << ans << endl;
}
Problem p02748 (C++)

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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> A(a);
  vector<int> B(b);
  vector<vector<int>> C(a, vector<int>(b, 0));
  for (int i = 0; i < a; i++)
    cin >> A[i];
  for (int j = 0; j < b; j++)
    cin >> B[j];
  int ans = 0;
  int minA = *min_element(A.begin(), A.end());
  int minB = *min_element(B.begin(), B.end());
  ans = minA + minB;
  for (int k = 0; k < m; k++) {
    int a_ind, b_ind, c;
    cin >> a_ind >> b_ind >> c;
    int tmp;
    tmp = A[a_ind - 1] + B[b_ind - 1] - c;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> A(a);
  vector<int> B(b);
  for (int i = 0; i < a; i++)
    cin >> A[i];
  for (int j = 0; j < b; j++)
    cin >> B[j];
  int ans = 0;
  int minA = *min_element(A.begin(), A.end());
  int minB = *min_element(B.begin(), B.end());
  ans = minA + minB;
  for (int k = 0; k < m; k++) {
    int a_ind, b_ind, c;
    cin >> a_ind >> b_ind >> c;
    int tmp;
    tmp = A[a_ind - 1] + B[b_ind - 1] - c;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}