alexjercan/bugnet huggingface dataset:
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int min_prime(int n);
int isprime(int n);

int main() {
  int n, p;
  while (1) {
    cin >> n >> p;
    if (n == -1 && p == -1)
      break;
    int prime_array[1000] = {0}, sum_array[50000] = {0};
    prime_array[0] = min_prime(n);
    for (int i = 0; i < (2 * p); i++) {
      prime_array[i + 1] = min_prime(prime_array[i]);
    }
    int k = 0;
    for (int i = 0; i < (2 * p) + 1; i++) {
      for (int j = i; j < (2 * p) + 1; j++) {
        sum_array[k] = prime_array[i] + prime_array[j];
        k++;
      }
    }
    sort(sum_array, sum_array + k);
    cout << sum_array[p - 1] << endl;
  }
  return 0;
}

int min_prime(int n) {
  while (++n) {
    if (isprime(n))
      break;
  }
  return n;
}

int isprime(int n) {
  int ans = 0;
  if (n == 0 || n == 1)
    ans = 0;
  else if (n == 2)
    ans = 1;
  else {
    for (int i = 2; i < n; i++) {
      if (i * i > n) {
        ans = 1;
        break;
      } else if (n % i == 0) {
        ans = 0;
        break;
      }
    }
  }
  return ans;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int min_prime(int n);
int isprime(int n);

int main() {
  int n, p;
  while (1) {
    cin >> n >> p;
    if (n == -1 && p == -1)
      break;
    int prime_array[1000] = {0}, sum_array[50000] = {0};
    if (isprime(n))
      prime_array[0] = n;
    else
      prime_array[0] = min_prime(n);
    for (int i = 0; i < (2 * p); i++) {
      prime_array[i + 1] = min_prime(prime_array[i]);
    }
    int k = 0;
    for (int i = 0; i < (2 * p) + 1; i++) {
      for (int j = i; j < (2 * p) + 1; j++) {
        sum_array[k] = prime_array[i] + prime_array[j];
        k++;
      }
    }
    sort(sum_array, sum_array + k);
    cout << sum_array[p - 1] << endl;
  }
  return 0;
}

int min_prime(int n) {
  while (++n) {
    if (isprime(n))
      break;
  }
  return n;
}

int isprime(int n) {
  int ans = 0;
  if (n == 0 || n == 1)
    ans = 0;
  else if (n == 2)
    ans = 1;
  else {
    for (int i = 2; i < n; i++) {
      if (i * i > n)
        ans = 1;
      else if (n % i == 0) {
        ans = 0;
        break;
      }
    }
  }
  return ans;
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}

bool is_prime(int n) {
  if (n == 0 || n == 1)
    return false;
  if (n == 2)
    return true;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

signed main() {
  while (true) {
    int N = read(), P = read();
    if (N == -1 && P == -1)
      break;
    vector<int> prime;
    vector<int> matsuzaki;
    ++N;
    while (1) { // O(P)
      if (is_prime(N)) {
        prime.push_back(N);
        REP(j, prime.size()) { // O(P)
          matsuzaki.push_back(prime[j] + N);
        }
        if (prime.size() >= P) {
          break;
        }
      }
      N++;
    }
    sort(matsuzaki.begin(), matsuzaki.end());
    cout << matsuzaki[P - 1] << endl;
  }
}

Error: TLE

Fixed submission:

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

using ll = long long;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)

int read() {
  int i;
  scanf("%lld", &i);
  return i;
}

bool is_prime(int n) {
  if (n == 0 || n == 1)
    return false;
  if (n == 2)
    return true;
  for (int i = 2; i < n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

signed main() {
  while (true) {
    int N = read(), P = read();
    if (N == -1 && P == -1)
      break;
    vector<int> prime;
    vector<int> matsuzaki;
    while (1) {
      if (is_prime(N)) {
        prime.push_back(N);
        REP(j, prime.size()) { matsuzaki.push_back(prime[j] + N); }
        sort(matsuzaki.begin(), matsuzaki.end());
        if (prime.size() >= P + 10) {
          // REP(i,prime.size()) cout << prime[i] << endl;
          cout << matsuzaki[P - 1] << endl;
          break;
        }
      }
      N++;
    }
  }
}
Problem p01268 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CH(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)

using namespace std;

int N, P;
bool flag[102000];
vector<int> v;

int main() {
  REP(i, 0, 102000) flag[i] = true;
  for (int i = 2; i < 102000; i++) {
    if (!flag[i])
      continue;
    v.push_back(i);
    for (int j = i * 2; j < 102000; j += i) {
      flag[j] = false;
    }
  }

  while (1) {
    cin >> N >> P;
    if (N == -1 && P == -1)
      break;
    int pos;
    REP(i, 0, v.size()) {
      if (N < v[i]) {
        pos = i;
        break;
      }
    }
    vector<int> tv, nums;
    int cnt = 0;
    REP(i, pos, v.size()) {
      if (cnt >= 1000)
        break;
      tv.push_back(v[i]);
      REP(j, 0, tv.size()) {
        cnt++;
        nums.push_back(v[i] + tv[j]);
      }
    }
    sort(nums.begin(), nums.end());
    cout << nums[P - 1] << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define CH(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)

using namespace std;

int N, P;
bool flag[102000];
vector<int> v;

int main() {
  REP(i, 0, 102000) flag[i] = true;
  for (int i = 2; i < 102000; i++) {
    if (!flag[i])
      continue;
    v.push_back(i);
    for (int j = i * 2; j < 102000; j += i) {
      flag[j] = false;
    }
  }

  while (1) {
    cin >> N >> P;
    if (N == -1 && P == -1)
      break;
    int pos;
    REP(i, 0, v.size()) {
      if (N < v[i]) {
        pos = i;
        break;
      }
    }
    vector<int> nums;
    REP(i, pos, v.size()) {
      REP(j, i, v.size()) {
        int num = v[i] + v[j];
        nums.push_back(num);
      }
    }
    sort(nums.begin(), nums.end());
    cout << nums[P - 1] << endl;
  }

  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int K = 150000;
bool A[K];
vector<int> prime;
void F() {
  for (int i = 0; i < K; i++)
    A[i] = true;

  A[0] = A[1] = false;
  for (int i = 0; i * i <= K; i++) {
    if (A[i])
      for (int j = 2; (i * j) < K; j++) {
        A[i * j] = false;
      }
  }
  for (int i = 0; i < K; i++) {
    if (A[i])
      prime.push_back(i);
  }
}

signed main() {

  F();
  while (1) {
    int N, P;
    cin >> N >> P;
    if (N == -1 && P == -1)
      break;

    N++;
    vector<int> v;
    while (A[N] == false)
      N++;
    int hoge = 0;
    for (int i = 0; i < prime.size(); i++) {
      if (prime[i] == N) {
        hoge = i;
        break;
      }
    }
    for (int i = hoge; i <= hoge + P; i++) {
      for (int j = 0; j < P; j++) {
        v.push_back(prime[i] + prime[i + j]);
      }
    }
    sort(v.begin(), v.end());

    cout << v[P - 1] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int K = 150000;
bool A[K];
vector<int> prime;
void F() {
  for (int i = 0; i < K; i++)
    A[i] = true;

  A[0] = A[1] = false;
  for (int i = 0; i * i <= K; i++) {
    if (A[i])
      for (int j = 2; (i * j) < K; j++) {
        A[i * j] = false;
      }
  }
  for (int i = 0; i < K; i++) {
    if (A[i])
      prime.push_back(i);
  }
}

signed main() {

  F();
  while (1) {
    int N, P;
    cin >> N >> P;
    if (N == -1 && P == -1)
      break;

    N++;
    vector<int> v;
    while (A[N] == false)
      N++;
    for (int i = 0; i < prime.size(); i++) {
      if (prime[i] < N)
        continue;
      for (int j = 0; j < P; j++) {
        v.push_back(prime[i] + prime[i + j]);
      }
    }
    sort(v.begin(), v.end());

    cout << v[P - 1] << endl;
  }

  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define N_MAX 110000

void dump(vector<int> &v, int n) {

  for (int i = 0; i < min(n, (int)v.size()); i++)
    cout << v[i] << " ";
  cout << endl;
}

int main() {

  bool is_pri[N_MAX] = {false};
  vector<int> pri;

  for (int i = 2; i < N_MAX; i++)
    is_pri[i] = true;

  for (int i = 2; i < N_MAX; i++) {
    if (is_pri[i]) {
      for (int j = 2; j * i < N_MAX; j++)
        is_pri[i * j] = false;
      pri.push_back(i);
    }
  }

  int N, P;
  while (cin >> N >> P) {
    if (N == -1)
      break;

    int first = upper_bound(pri.begin(), pri.end(), N) - pri.begin();

    vector<int> ans(P, INT_MAX);
    for (int i = first; i < min(first + P, (int)pri.size()); i++) {
      for (int j = i; j < min(first + P, (int)pri.size()); j++) {

        ans.push_back(pri[i] + pri[j]);
        sort(ans.begin(), ans.end());
        ans.pop_back();
      }
    }
    cout << ans[P - 1] << endl;
  }
}

Error: TLE

Fixed submission:

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

#define N_MAX 110000

void dump(vector<int> &v, int n) {

  for (int i = 0; i < min(n, (int)v.size()); i++)
    cout << v[i] << " ";
  cout << endl;
}

int main() {

  bool is_pri[N_MAX] = {false};
  vector<int> pri;

  for (int i = 2; i < N_MAX; i++)
    is_pri[i] = true;

  for (int i = 2; i < N_MAX; i++) {
    if (is_pri[i]) {
      for (int j = 2; j * i < N_MAX; j++)
        is_pri[i * j] = false;
      pri.push_back(i);
    }
  }

  //	  dump(pri,100);
  //	  cout << pri.size() << endl;
  int N, P;
  while (cin >> N >> P) {
    if (N == -1)
      break;

    int i = upper_bound(pri.begin(), pri.end(), N) - pri.begin();
    //			cout << pri[i] << endl;
    vector<int> ans(P, INT_MAX);

    for (int j = i; j < pri.size(); j++) {
      for (int k = j; k < pri.size(); k++) {
        ans.push_back(pri[j] + pri[k]);
        sort(ans.begin(), ans.end());
        ans.pop_back();
        //						dump(ans,1000);
      }
    }
    cout << ans[P - 1] << endl;
  }
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define print(a) cout << a << "\\n"
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\\n'

#define MAX 250000

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

  int prim[MAX];
  REP(i, MAX) { prim[i] = 1; }
  prim[0] = 0;
  prim[1] = 0;
  FOR(i, 2, sqrt(MAX)) {
    if (prim[i] == 0)
      continue;
    FOR(j, 2, MAX) {
      if (i * j > MAX) {
        break;
      }
      prim[i * j] = 0;
    }
  }

  vector<int> p;
  REP(i, MAX) {
    if (prim[i] == 1) {
      p.push_back(i);
    }
  }

  bool flag = true;
  int N, P;

  while (true) {
    int count = 0;
    cin >> N >> P;
    if (N + P == -2)
      break;

    vector<int> sum;

    REP(i, p.size()) {
      if (count > 15) {
        break;
      }
      if (p[i] > N) {
        count++;
        FOR(j, i, P + i) { sum.push_back(p[i] + p[j]); }
      }
    }

    sort(ALL(sum));

    cout << sum[P - 1] << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define print(a) cout << a << "\\n"
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\\n'

#define MAX 250000

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

  int prim[MAX];
  REP(i, MAX) { prim[i] = 1; }
  prim[0] = 0;
  prim[1] = 0;
  FOR(i, 2, sqrt(MAX)) {
    FOR(j, 2, MAX) {
      if (i * j > MAX) {
        break;
      }
      prim[i * j] = 0;
    }
  }

  vector<int> p;
  REP(i, MAX) {
    if (prim[i] == 1) {
      p.push_back(i);
    }
  }

  while (true) {
    vector<int> sum;
    int N, P;
    cin >> N >> P;
    if (N + P == -2)
      break;

    REP(i, p.size()) {
      if (p[i] > N) {
        FOR(j, i, P + i) { sum.push_back(p[i] + p[j]); }
      }
    }

    sort(ALL(sum));

    cout << sum[P - 1] << endl;
  }

  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

#define all(c) (c).begin(), (c).end()

using namespace std;

vector<int> p, v;
bool fg[101000];

int main(void) {

  for (int i = 2; i * i < 101000; i++) {
    if (!fg[i]) {
      for (int j = i * i; j < 101000; j += i) {
        fg[j] = true;
      }
    }
  }
  for (int i = 2; i < 101000; i++)
    if (!fg[i])
      p.push_back(i);

  int N, P;
  while (cin >> N >> P, 0 <= N && 0 <= P) {
    int b = upper_bound(all(p), N) - p.begin();
    int psize = p.size();
    v.clear();
    for (int i = b; i - b < P && i < psize; i++) {
      for (int j = i; j - i < P && j < psize; j++) {
        v.push_back(p[i] + p[j]);
      }
    }
    sort(all(v));
    cout << v[P - 1] << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

#define all(c) (c).begin(), (c).end()

using namespace std;

vector<int> p, v;
bool fg[101000];

int main(void) {

  for (int i = 2; i * i < 101000; i++) {
    if (!fg[i]) {
      for (int j = i * i; j < 101000; j += i) {
        fg[j] = true;
      }
    }
  }
  for (int i = 2; i < 101000; i++)
    if (!fg[i])
      p.push_back(i);

  int N, P;
  while (cin >> N >> P, 0 <= N && 0 <= P) {
    int b = upper_bound(all(p), N) - p.begin();

    v.clear();
    for (int i = b; i < p.size(); i++) {
      for (int j = i; j < p.size(); j++) {
        v.push_back(p[i] + p[j]);
      }
    }
    sort(all(v));
    cout << v[P - 1] << endl;
  }

  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define pb push_back
#define all(v) v.begin(), v.end()
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define MAXBOOL 500000
using namespace std;

int main() {
  int n, p;
  vector<int> prime;
  bool check[MAXBOOL];
  while (cin >> n >> p, n != -1 || p != -1) {
    prime.clear();
    fill(check, check + MAXBOOL, true);
    check[0] = check[1] = false;
    loop(i, 2, sqrt(MAXBOOL)) {
      for (int j = i * 2; j < MAXBOOL; j += i) {
        check[j] = false;
      }
    }
    int cnt = 0;
    while (prime.size() <= 200) {
      if (check[n + 1 + cnt])
        prime.pb(n + 1 + cnt);
      cnt++;
    }
    vector<int> ans;
    rep(i, prime.size()) {
      loop(j, i, prime.size()) { ans.pb(prime[i] + prime[j]); }
    }
    sort(all(ans));
    cout << ans[p - 1] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define pb push_back
#define all(v) v.begin(), v.end()
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define MAXBOOL 1000000
using namespace std;

int main() {
  int n, p;
  vector<int> prime;
  bool check[MAXBOOL];
  while (cin >> n >> p, n != -1 || p != -1) {
    prime.clear();
    fill(check, check + MAXBOOL, true);
    check[0] = check[1] = false;
    loop(i, 2, sqrt(MAXBOOL)) {
      for (int j = i * 2; j < MAXBOOL; j += i) {
        check[j] = false;
      }
    }
    int cnt = 0;
    while (prime.size() <= 200) {
      if (check[n + 1 + cnt])
        prime.pb(n + 1 + cnt);
      cnt++;
    }
    vector<int> ans;
    rep(i, prime.size()) {
      loop(j, i, prime.size()) { ans.pb(prime[i] + prime[j]); }
    }
    sort(all(ans));
    cout << ans[p - 1] << endl;
  }
  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

using namespace std;

#define A 5011
#define PRI 1000
#define PRIME 1100000

int main(int argc, char *argv[]) {

  int N, P;
  int i, j, cnt = 0;
  int prime[PRI], a[A];
  bool isprime[PRIME];

  fill(isprime, isprime + PRIME, true);
  isprime[0] = false;
  isprime[1] = false;

  for (i = 2; i < PRIME + 1; i++) {
    isprime[i] = true;
  }

  cnt = 0;
  for (i = 2; i < PRIME + 1; i++) {
    if (isprime[i]) {
      //	printf("%d is prime\\n", i);
      for (j = 2; j < PRIME / i; j++) {
        isprime[i * j] = false;
      }
    }
  }

  while (true) {

    fill(a, a + A, 0);
    fill(prime, prime + PRI, 0);

    scanf("%d %d", &N, &P);
    if (N == -1 && P == -1) {
      break;
    }

    cnt = 0;
    for (i = N + 1; i < PRIME; i++) {
      if (cnt == 100) {
        break;
      }
      if (cnt < 100 && isprime[i]) {
        prime[cnt++] = i;
        //	printf("%d is selected prime\\n", prime[cnt-1]);
      }
    }

    cnt = 0;
    for (i = 0; i < 100; i++) {
      for (j = 0; j < i + 1; j++) {
        a[cnt++] = prime[i] + prime[j];
        //     	printf("%d is %dth sum of two primes\\n", a[cnt-1], cnt-1);
      }
    }

    sort(a, a + 5010);

    printf("%d\\n", a[P - 1]);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

#define A 1000000
#define PRI 1002
#define PRIME 1000000

int main(int argc, char *argv[]) {

  int N, P;
  int i, j, cnt = 0;
  int prime[PRI], a[A];
  bool isprime[PRIME];

  fill(isprime, isprime + PRIME, true);
  isprime[0] = false;
  isprime[1] = false;

  for (i = 2; i < PRIME + 1; i++) {
    isprime[i] = true;
  }

  cnt = 0;
  for (i = 2; i < PRIME + 1; i++) {
    if (isprime[i]) {
      //	printf("%d is prime\\n", i);
      for (j = 2; j < PRIME / i; j++) {
        isprime[i * j] = false;
      }
    }
  }

  while (true) {

    fill(a, a + A, 0);
    fill(prime, prime + PRI, 0);

    scanf("%d %d", &N, &P);
    if (N == -1 && P == -1) {
      break;
    }

    cnt = 0;
    for (i = 0; i < PRIME; i++) {
      if (i > N && cnt < 1000 && isprime[i]) {
        prime[cnt++] = i;
        //	printf("%d is selected prime\\n", prime[cnt-1]);
      }
    }

    cnt = 0;
    for (i = 0; i < 1000; i++) {
      for (j = 0; j < i + 1; j++) {
        a[cnt++] = prime[i] + prime[j];
        //     	printf("%d is %dth sum of two primes\\n", a[cnt-1], cnt-1);
      }
    }

    sort(a, a + 500500);

    for (i = 0; i < 10000; i++) {
      //      printf("%dth sum is %d\\n", i, a[i]);
    }

    printf("%d\\n", a[P - 1]);
  }

  return 0;
}
Problem p01268 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int a[100000] = {2, 3}, i, j, k, c = 2, b[100002][101], q, w[700];
int main() {
  for (i = 4; i < 150000; i++) {
    for (k = 1, j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        k = 0;
        break;
      }
    }
    if (k)
      a[c++] = i;
  }
  k = 0;
  for (i = 0; i <= 100000; i++) {
    if (i >= a[k])
      k++;
    for (q = 0, j = k; j < k + 25; j++) {
      for (c = j; c < j + 25; c++) {
        w[q++] = a[j] + a[c];
      }
    }
    sort(w, w + q - 1);
    for (c = 0; c <= 100; c++)
      b[i][c] = w[c];
  }
  while (cin >> i >> j) {
    if (i < 0)
      break;
    cout << b[i][j - 1] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[10000] = {2, 3}, i, j, k, c = 2, b[100002][101], q;
int main() {
  for (i = 4; i < 150000; i++) {
    for (k = 1, j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        k = 0;
        break;
      }
    }
    if (k)
      a[c++] = i;
  }
  k = 0;
  for (i = 0; i <= 100000; i++) {
    if (i > a[k])
      k++;
    for (q = 0, j = k; j < k + 20; j++) {
      for (c = j; c < j + 20; c++) {
        b[i][q++] = a[j] + a[c];
      }
    }
    sort(b[i], b[i] + q - 1);
  }
  while (cin >> i >> j) {
    if (i < 0)
      break;
    cout << b[i][j - 1] << endl;
  }
}
Problem p01268 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> result;
  int i, j, n, p, k, data[110000], primenum[100000];
  for (i = 0; i < 100001; i++) {
    data[i] = 0;
  }

  for (i = 0; i < 100000; i++) {
    primenum[i] = 0;
  }

  for (i = 2; i * i < 110000; i++) {
    if (data[i] == 0) {
      for (j = 2 * i; j < 110000; j += i) {
        data[j] = 1;
      }
    }
  }
  data[0] = 1;
  data[1] = 1;

  while (1) {
    result.clear();
    cin >> n >> p;
    if (n == -1 && p == -1)
      break;
    j = 0;
    for (i = n + 1; i < 110000; i++) {
      if (data[i] == 0) {
        primenum[j] = i;
        j++;
        if (j == 1000)
          break;
      }
    }

    // for(i = 0; i < 30; i++){
    //  cout <<"primenum[" << i << "]" << primenum[i] << endl;
    //  }
    for (i = 0; i < 100; i++) {
      for (k = i; k < 100; k++) {
        result.push_back(primenum[i] + primenum[k]);
        //	cout << "primenum[i]" <<primenum[i] <<"primenum[k]" <<
        //primenum[k] << endl;
      }
    }

    sort(result.begin(), result.end());
    // for(i = 0; i < 100; i++){
    //	cout << "result[" <<i<< "]"<<result[i] << endl;
    // }
    cout << result[p - 1] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> result;
  int i, j, n, p, k, data[1010000], primenum[100000];
  for (i = 0; i < 1100000; i++) {
    data[i] = 0;
    primenum[i] = 0;
  }

  for (i = 0; i < 100000; i++) {
    primenum[i] = 0;
  }

  for (i = 2; i * i < 1010000; i++) {
    if (data[i] == 0) {
      for (j = 2 * i; j < 1010000; j += i) {
        data[j] = 1;
      }
    }
  }
  data[0] = 1;
  data[1] = 1;

  while (1) {
    result.clear();
    cin >> n >> p;
    if (n == -1 && p == -1)
      break;
    j = 0;
    for (i = n + 1; i < 1010000; i++) {
      if (data[i] == 0) {
        primenum[j] = i;
        j++;
        if (j == 1000)
          break;
      }
    }

    // for(i = 0; i < 30; i++){
    //  cout <<"primenum[" << i << "]" << primenum[i] << endl;
    //  }
    for (i = 0; i < 100; i++) {
      for (k = i; k < 100; k++) {
        result.push_back(primenum[i] + primenum[k]);
        //	cout << "primenum[i]" <<primenum[i] <<"primenum[k]" <<
        //primenum[k] << endl;
      }
    }

    sort(result.begin(), result.end());
    // for(i = 0; i < 100; i++){
    //	cout << "result[" <<i<< "]"<<result[i] << endl;
    // }
    cout << result[p - 1] << endl;
  }
  return 0;
}