Problem p00734 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

int main() {
  for (int n, m; cin >> n >> m, (n | m) != 0;) {
    int taro[100], hanako[100];
    int t_sum = 0, h_sum = 0;
    rep(i, n) {
      cin >> taro[i];
      t_sum += taro[i];
    }
    rep(i, m) {
      cin >> hanako[i];
      h_sum += hanako[i];
    }

    int ans_t, ans_h;
    int min = INF;
    rep(i, n) rep(j, m) {
      int t = t_sum - taro[i] + hanako[j];
      int h = h_sum - hanako[j] + taro[i];

      if (t == h && min > taro[i] + hanako[j]) {
        min = taro[i] + hanako[j];
        ans_t = taro[i];
        ans_h = hanako[j];
      }
    }

    if (min == INF)
      cout << -1 << endl;
    else
      cout << ans_t << ' ' << ans_h << endl;
  }

  return 0;
}

Error: 0
> "#" = #
> "#" = #
> "#" = #
> "#" = #
> "#" = #


Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

int main() {
  for (int n, m; cin >> n >> m, (n | m) != 0;) {
    int taro[100], hanako[100];
    int t_sum = 0, h_sum = 0;
    rep(i, n) {
      cin >> taro[i];
      t_sum += taro[i];
    }
    rep(i, m) {
      cin >> hanako[i];
      h_sum += hanako[i];
    }

    int ans_t, ans_h;
    int min = INF;
    rep(i, n) rep(j, m) {
      int t = t_sum - taro[i] + hanako[j];
      int h = h_sum - hanako[j] + taro[i];

      if (t == h && min > taro[i] + hanako[j]) {
        min = taro[i] + hanako[j];
        ans_t = taro[i];
        ans_h = hanako[j];
      }
    }

    dump("#");
    if (min == INF)
      cout << -1 << endl;
    else
      cout << ans_t << ' ' << ans_h << endl;
  }

  return 0;
}