Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <cassert>
#include <ccomplex>
#include <clocale>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <valarray>
#include <vector>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int xcomp(vector<LL> &a, vector<LL> &b) { return a[0] < b[0]; }

#define XSORT(c) sort((c).begin(), (c).end(), xcomp)

#define ALL(x) (x).begin(), (x).end()
LL mod = 1000000007;

int main() {
  LL N, M;
  cin >> N >> M;
  vector<vector<LL>> v(N, vector<LL>(2, 0));
  vector<vector<LL>> vv(N, vector<LL>(2, 0));
  REP(i, N) { cin >> v[i][0] >> v[i][1]; }
  REP(i, M) { cin >> vv[i][0] >> vv[i][1]; }
  REP(i, N) {
    LL min = 900000000;
    LL flag = 0;
    REP(j, M) {
      LL sum = 0;
      if (v[i][0] - vv[j][0] > 0) {
        sum += (v[i][0] - vv[j][0]);
      } else {
        sum -= (v[i][0] - vv[j][0]);
      }
      if (v[i][1] - vv[j][1] > 0) {
        sum += (v[i][1] - vv[j][1]);
      } else {
        sum -= (v[i][1] - vv[j][1]);
      }
      if (min > sum) {
        min = sum;
        flag = j + 1;
      }
    }
    cout << flag << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <cassert>
#include <ccomplex>
#include <clocale>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <utility>
#include <valarray>
#include <vector>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int xcomp(vector<LL> &a, vector<LL> &b) { return a[0] < b[0]; }

#define XSORT(c) sort((c).begin(), (c).end(), xcomp)

#define ALL(x) (x).begin(), (x).end()
LL mod = 1000000007;

int main() {
  LL N, M;
  cin >> N >> M;
  vector<vector<LL>> v(N, vector<LL>(2, 0));
  vector<vector<LL>> vv(M, vector<LL>(2, 0));
  REP(i, N) { cin >> v[i][0] >> v[i][1]; }
  REP(i, M) { cin >> vv[i][0] >> vv[i][1]; }
  REP(i, N) {
    LL min = 900000000;
    LL flag = 0;
    REP(j, M) {
      LL sum = 0;
      if (v[i][0] - vv[j][0] > 0) {
        sum += (v[i][0] - vv[j][0]);
      } else {
        sum -= (v[i][0] - vv[j][0]);
      }
      if (v[i][1] - vv[j][1] > 0) {
        sum += (v[i][1] - vv[j][1]);
      } else {
        sum -= (v[i][1] - vv[j][1]);
      }
      if (min > sum) {
        min = sum;
        flag = j + 1;
      }
    }
    cout << flag << endl;
  }
}