Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
#define MAX 9e5
using namespace std;
typedef pair<int, int> pii;
int main() {
  vector<bool> Primecheck(MAX + 1, true);
  vector<int> Primenumber(MAX + 1, 0); // Primearray
  int Primecounter = 0;                // Primearray counter;
  for (int i = 2; i < MAX + 1; i++) {
    if (Primecheck[i]) {
      for (int j = 2; i * j < MAX; j++)
        Primecheck[i * j] =
            false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
      Primenumber[Primecounter] = i;
      Primecounter++;
    }
  }
  int n, m;
  while (cin >> n >> m, n + m >= 0) {
    int cnt = 0;
    for (int i = 0; i < Primenumber.size(); i++) {
      if (Primenumber[i] > n) {
        cnt = i;
        break;
      }
    }
    vi v;
    for (int i = cnt; i <= cnt + m; i++) {
      for (int j = i; j <= cnt + m; j++) {
        v.push_back(Primenumber[i] + Primenumber[j]);
      }
    }
    sort(all(v));
    cout << v[m - 1] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 1e7
int main() {
  int n, n2;
  vector<bool> check(MAX + 1, true);
  vector<int> Primenumber(MAX + 1, 0); // Primearray
  int counter = 0;                     // Primearray counter;
  for (int i = 2; i < MAX + 1; i++) {
    if (check[i]) {
      for (int j = 2; i * j < MAX; j++)
        check[i * j] =
            false; //?´???°??????Primearray???????´??????????????????°?????¨???false???
      Primenumber[counter] = i;
      counter++;
    }
  }
  check[0] = false;
  check[1] = false;
  while (cin >> n >> n2, n + n2 + 2) {
    vi v;
    int count = 0;
    for (int i = 2 * n;; i++) {
      if (i < 4)
        continue;
      // cout<<i<<endl;
      for (int j = i; (double)j >= (double)i / 2; j--) {
        if (check[j] && check[i - j] && i - j > n && j > n) {
          v.push_back(i);
          count++;
        }
        if (count > n2)
          goto E;
      }
    }
  E:
    cout << v[n2 - 1] << endl;
  }
}