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

#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef vector<vector<int>> vector2d;

int main() {

  int n, m;

  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    int i, j, temp, sumtaro = 0, sumhanako = 0, ansnum, diffe1, diffe2;
    vector<int> taro, hanako;
    vector2d ans;
    ans.resize(3);

    // 太郎の入力、sumを計算しpushbackは重複をさける
    for (i = 0; i < n; i++) {
      cin >> temp;
      sumtaro += temp;
      if (find(taro.begin(), taro.end(), temp) == taro.end()) {
        taro.push_back(temp);
      }
    }

    // 花子の入力、同様に
    for (i = 0; i < m; i++) {
      cin >> temp;
      sumhanako += temp;
      if (find(hanako.begin(), hanako.end(), temp) == hanako.end()) {
        hanako.push_back(temp);
      }
    }

    // メイン処理
    diffe1 = (sumtaro - sumhanako); // マイナス→たろー少ない

    if (diffe1 % 2 == 0) {
      diffe1 = diffe1 / 2;

      for (i = 0; i < taro.size(); i++) {
        for (j = 0; j < hanako.size(); j++) {
          diffe2 = taro[i] - hanako[j];
          if (diffe2 == diffe1) {
            ans[0].push_back(taro[i]);
            ans[1].push_back(hanako[j]);
            ans[2].push_back(taro[i] + hanako[j]);
          }
        }
      }
    }

    if (ans[2].size() == 0) {
      cout << -1 << endl;
    } else {
      ansnum = 0;
      for (i = 1; i < ans[2].size(); i++) {
        if (ans[2][ansnum] > ans[2][i]) {
          ansnum = i;
        }
      }
      cout << ans[0][ansnum] << " " << ans[1][ansnum] << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef vector<vector<int>> vector2d;

int main() {

  int n, m;

  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;

    int i, j, temp, sumtaro = 0, sumhanako = 0, ansnum, diffe1, diffe2;
    vector<int> taro, hanako;
    vector2d ans;
    ans.reserve(3);

    // 太郎の入力、sumを計算しpushbackは重複をさける
    for (i = 0; i < n; i++) {
      cin >> temp;
      sumtaro += temp;
      if (find(taro.begin(), taro.end(), temp) == taro.end()) {
        taro.push_back(temp);
      }
    }

    // 花子の入力、同様に
    for (i = 0; i < m; i++) {
      cin >> temp;
      sumhanako += temp;
      if (find(hanako.begin(), hanako.end(), temp) == hanako.end()) {
        hanako.push_back(temp);
      }
    }

    // cout << "b" << endl;
    // メイン処理
    diffe1 = (sumtaro - sumhanako) / 2;
    if (diffe1 < 0)
      diffe1 = diffe1 * (-1);

    for (i = 0; i < taro.size(); i++) {
      for (j = 0; j < hanako.size(); j++) {
        diffe2 = taro[i] - hanako[j];
        if (diffe2 < 0)
          diffe2 = diffe2 * (-1);
        if (diffe2 == diffe1) {
          ans[0].push_back(taro[i]);
          ans[1].push_back(hanako[j]);
          ans[2].push_back(taro[i] + hanako[j]);
        }
      }
    }

    // cout << "a" << endl;

    if (ans[2].size() == 0) {
      cout << -1 << endl;
    } else {
      ansnum = 0;
      for (i = 1; i < ans[2].size(); i++) {
        if (ans[2][ansnum] > ans[2][i]) {
          ansnum = i;
        }
      }
      cout << ans[0][ansnum] << " " << ans[1][ansnum] << endl;
    }
  }

  return 0;
}