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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i < int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {

  int n, a;
  vector<int> v;
  cin >> n;
  rep(i, n) {
    cin >> a;

    v.push_back(a);
  }

  sort(v.begin(), v.end());

  int p, q;
  vector<int> s;
  if (n == 3)
    q = 3;
  else
    q = 4;
  rep(i, q) {
    rep(j, q) {
      if (i != j) {
        if (v[j] / 10000 != 0) {
          p = 100000 * v[i] + v[j];
          s.push_back(p);
        } else if (v[j] / 1000 != 0) {
          p = 10000 * v[i] + v[j];
          s.push_back(p);
        } else if (v[j] / 100 != 0) {
          p = 1000 * v[i] + v[j];
          s.push_back(p);
        } else if (v[j] / 10 != 0) {
          p = 100 * v[i] + v[j];
          s.push_back(p);
        } else {
          p = 10 * v[i] + v[j];
          s.push_back(p);
        }
      }
    }
  }

  sort(s.begin(), s.end());

  cout << s[2] << endl;

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i < int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {

  int n, a;
  vector<int> v;
  cin >> n;
  rep(i, n) {
    cin >> a;

    v.push_back(a);
  }

  sort(v.begin(), v.end());

  int p;
  vector<int> s;

  rep(i, n) {
    rep(j, n) {
      if (i != j) {
        if (v[j] / 10000 != 0) {
          p = 100000 * v[i] + v[j];
          s.push_back(p);
        } else if (v[j] / 1000 != 0) {
          p = 10000 * v[i] + v[j];
          s.push_back(p);
        } else if (v[j] / 100 != 0) {
          p = 1000 * v[i] + v[j];
          s.push_back(p);
        } else if (v[j] / 10 != 0) {
          p = 100 * v[i] + v[j];
          s.push_back(p);
        } else {
          p = 10 * v[i] + v[j];
          s.push_back(p);
        }
      }
    }
  }

  sort(s.begin(), s.end());

  cout << s[2] << endl;

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
ll a[10000];
ll first = INF, second = INF, third = INF;
int digit(ll p) {
  if (p == 0ll)
    return 1;
  int res = 0;
  while (p > 0ll)
    p /= 10ll, res++;
  return res;
}
void update(ll k) {
  if (k < first)
    third = second, second = first, first = k;
  else if (k < second)
    third = second, second = k;
  else if (k < third)
    third = k;
}
int main() {
  vector<ll> vec;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ll k = ((ll)pow(10, digit(a[i]))) * a[j] + a[i];
      update(k);
      k = ((ll)pow(10, digit(a[j]))) * a[i] + a[j];
      update(k);
    }
  }
  cout << third << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
ll a[10000];
int digit(ll p) {
  if (p == 0ll)
    return 1;
  int res = 0;
  while (p > 0ll)
    p /= 10ll, res++;
  return res;
}
int main() {
  vector<ll> vec;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ll k = ((ll)pow(10, digit(a[i]))) * a[j] + a[i];
      vec.pb(k);
      k = ((ll)pow(10, digit(a[j]))) * a[i] + a[j];
      vec.pb(k);
    }
  }
  SORT(vec);
  cout << vec[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int brute(vector<int> v) {
  vector<int> tmp;
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i == j)
        continue;
      tmp.push_back(stoi(to_string(v[i]) + to_string(v[j])));
    }
  }
  sort(tmp.begin(), tmp.end());
  return tmp[2];
}

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &e : v) {
    cin >> e;
  }
  sort(v.begin(), v.end());
  if (n <= 10) {
    cout << brute(v) << endl;
    return 0;
  }
  vector<int> s(v.begin(), v.begin() + 10);
  cout << brute(s) << endl;

  return 0;
}


Error: MLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &e : v) {
    cin >> e;
  }
  vector<int> tmp;
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i == j)
        continue;
      tmp.push_back(stoi(to_string(v[i]) + to_string(v[j])));
    }
  }
  sort(tmp.begin(), tmp.end());
  cout << tmp[2] << endl;

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

string str_int(long long int num) {
  string str = "";
  bool minus = false;
  if (num < 0) {
    minus = true;
    num = -num;
  } else if (num == 0) {
    str = "0";
    return str;
  }
  while (true) {
    if (num == 0) {
      break;
    }
    string d = "D";
    d[0] = '0' + (num % 10);
    str = d + str;
    num /= 10;
  }
  if (minus) {
    str = "-" + str;
  }
  return str;
}

long long int int_str(string str) {
  long long int num = 0;
  bool minus = false;
  if (str[0] == '-') {
    str = str.substr(1);
    minus = true;
  }
  for (int i = 0; i < str.size(); i++) {
    num *= 10;
    num += (str[i] - '0');
  }
  if (minus) {
    num = -num;
  }
  return num;
}

int main() {

  int N;

  cin >> N;

  vector<long long int> v, v2;

  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    v.push_back(num);
  }

  sort(v.begin(), v.end());

  for (int i = 0; i < v.size(); i++) {
    if (i > 10) {
      break;
    }
    for (int j = i + 1; j < v.size(); j++) {
      if (j > 10) {
        break;
      }
      v2.push_back(int_str(str_int(v[i]) + str_int(v[j])));
      v2.push_back(int_str(str_int(v[j]) + str_int(v[i])));
    }
  }

  sort(v2.begin(), v2.end());

  cout << v2[2] << endl;

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

string str_int(long long int num) {
  string str = "";
  bool minus = false;
  if (num < 0) {
    minus = true;
    num = -num;
  } else if (num == 0) {
    str = "0";
    return str;
  }
  while (true) {
    if (num == 0) {
      break;
    }
    string d = "D";
    d[0] = '0' + (num % 10);
    str = d + str;
    num /= 10;
  }
  if (minus) {
    str = "-" + str;
  }
  return str;
}

long long int int_str(string str) {
  long long int num = 0;
  bool minus = false;
  if (str[0] == '-') {
    str = str.substr(1);
    minus = true;
  }
  for (int i = 0; i < str.size(); i++) {
    num *= 10;
    num += (str[i] - '0');
  }
  if (minus) {
    num = -num;
  }
  return num;
}

string str[20000];

int main() {

  int N;

  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> str[i];
  }

  vector<long long int> v;

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      string str1 = str[i] + str[j];
      string str2 = str[j] + str[i];
      long long int num1 = int_str(str1);
      long long int num2 = int_str(str2);
      v.push_back(num1);
      v.push_back(num2);
    }
  }

  sort(v.begin(), v.end());

  cout << v[2] << endl;

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


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define first F
#define second S

typedef vector<int> vi;
typedef pair<int, int> pii;

char s1[100000000];
char s2[100000000];

int main(void) {
  int i, j, n;
  cin >> n;
  vi a(n), ans;
  rep(i, n) cin >> a[i];
  sort(all(a));
  rep(i, min(n, 5)) rep(j, min(n, 5)) if (i != j) {
    int t = a[i];
    int tmp = a[j];
    for (; tmp; tmp /= 10)
      t *= 10;
    ans.push_back(t + a[j]);
  }
  sort(all(ans));
  cout << ans[2] << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define first F
#define second S

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  vi v;
  rep(i, n) rep(j, n) if (i != j) {
    string tmp = s[i] + s[j];
    v.push_back(atoi(tmp.c_str()));
  }
  sort(all(v));
  cout << v[2] << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
priority_queue<int> Q;
int a[10010], n;

int P(int x, int y) {
  int r = 10;
  while (x >= r)
    r *= 10;
  return r * y + x;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < i; j++) {
      Q.push(P(a[i], a[j]));
      Q.push(P(a[j], a[i]));
    }
    while (Q.size() > 3)
      Q.pop();
  }
  cout << Q.top() << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
priority_queue<int> Q;
int a[1010], n;

int P(int x, int y) {
  int r = 10;
  while (x >= r)
    r *= 10;
  return r * y + x;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < i; j++) {
      Q.push(P(a[i], a[j]));
      Q.push(P(a[j], a[i]));
    }
    while (Q.size() > 3)
      Q.pop();
  }
  cout << Q.top() << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int a[10234];
vector<int> v;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < 3; i++)
    v.push_back(1 << 30);

  sort(a, a + n);
  for (int i = 0; i < min(n, 8); i++) {
    for (int j = 0; j < min(8, n); j++) {
      if (i == j)
        continue;
      string s = to_string(a[i]);
      string b = to_string(a[j]);
      s += b;
      int c = stoi(s);
      if (v[2] >= c) {
        v.push_back(c);
        if (v[3] < v[2])
          swap(v[3], v[2]);
        if (v[2] < v[1])
          swap(v[2], v[1]);
        if (v[1] < v[0])
          swap(v[1], v[0]);
        v.pop_back();
      }
    }
  }
  cout << v[2] << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int a[10234];
vector<int> v;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < 3; i++)
    v.push_back(1 << 30);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      string s = to_string(a[i]);
      string b = to_string(a[j]);
      s += b;
      int c = stoi(s);
      if (v[2] >= c) {
        v.push_back(c);
        if (v[3] < v[2])
          swap(v[3], v[2]);
        if (v[2] < v[1])
          swap(v[2], v[1]);
        if (v[1] < v[0])
          swap(v[1], v[0]);
        v.pop_back();
      }
    }
  }
  cout << v[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    vector<long long> A;
    vector<long long> ans;
    rep(i, n) {
      int inp;
      cin >> inp;
      A.push_back(inp);
    }
    sort(A.begin(), A.end());
    long long t, a, l;
    rep(i, 5) {
      rep(j, 5) {
        if (i == j)
          continue;
        t = (int)log10(A[j]);
        a = A[i];
        rep(k, t + 1) { a *= 10; }
        ans.push_back(a + A[j]);
      }
    }
    sort(ans.begin(), ans.end());
    cout << ans[2] << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int n;
  vector<int> A;
  vector<long long> ans;
  while (cin >> n) {
    rep(i, n) {
      int inp;
      cin >> inp;
      A.push_back(inp);
    }
    sort(A.begin(), A.end());
    long long num[6];
    int t, a, l;
    rep(i, n) {
      rep(j, n) {
        if (i == j)
          continue;
        t = (int)log10(A[j]);
        a = A[i];
        rep(k, t + 1) { a *= 10; }
        ans.push_back(a + A[j]);
      }
    }
    sort(ans.begin(), ans.end());
    cout << ans[2] << endl;
  }
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  int n, num;
  cin >> n;
  vector<string> vec(n);
  vector<int> vec_alpha(n - 1);
  vector<int> vec_beta(0);
  for (int i = 0; i < n; i++)
    cin >> vec[i];
  for (int i = 0; i < n; i++) {
    num = 0;
    for (int j = 0; j < n; j++)
      if (i != j) {
        vec_alpha[num] = stoi(vec[i] + vec[j]);
        num++;
      }
    sort(vec_alpha.begin(), vec_alpha.end());
    vec_beta.push_back(vec_alpha[0]);
    vec_beta.push_back(vec_alpha[1]);
    vec_beta.push_back(vec_alpha[2]);
  }
  sort(vec_beta.begin(), vec_beta.end());
  cout << vec_beta[2] << endl;
  return 0;
}


Error: MLE

Fixed submission:

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

int main() {
  int i, j, n;
  cin >> n;
  int num = 0;
  vector<string> vec(n);
  vector<int> vec_alpha(n * (n - 1));
  for (i = 0; i < n; i++)
    cin >> vec[i];
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      if (i != j) {
        vec_alpha[num] = stoi(vec[i] + vec[j]);
        num++;
      }
  sort(vec_alpha.begin(), vec_alpha.end());
  cout << vec_alpha[2] << endl;
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string str, s1, s2;
  int n;
  cin >> n;
  vector<int> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  sort(data.begin(), data.end());
  vector<int> ddata;
  for (int i = 0; i < min(20, n); i++) {
    for (int j = 0; j < min(20, n); j++) {
      if (i == j)
        continue;
      int left = data[i], right = data[j];
      while (right != 0)
        right /= 10, left *= 10;
      ddata.push_back(left + data[j]);
    }
  }
  sort(ddata.begin(), ddata.end());
  cout << ddata[2] << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string str, s1, s2;
  int n;
  cin >> n;
  vector<string> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  vector<int> ddata;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      s1 = data[i] + data[j];
      s2 = data[j] + data[i];
      ddata.push_back(atoi(s1.c_str()));
      ddata.push_back(atoi(s2.c_str()));
    }
  }
  sort(ddata.begin(), ddata.end());
  cout << ddata[2] << endl;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)), (x).end())

typedef long long ll;

const int INF = 1 << 29;

void solve(void) {
  int N;
  cin >> N;
  vector<string> ss;
  int ns[3] = {INF};
  rep(N, i) {
    string s;
    cin >> s;
    ss.pb(s);
  }
  rep(N - 1, i) Rep(i + 1, N - 1, j) {
    int a[2] = {stoi(ss[i] + ss[j]), stoi(ss[j] + ss[i])};
    rep(2, j) rep(3, i) {
      if (ns[i] > a[j]) {
        Repr(1, i, k) ns[k + 1] = ns[k];
        ns[i] = a[j];
        break;
      }
    }
  }
  printf("%d\\n", ns[2]);
}

int main(void) {
  solve();
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)), (x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; // Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int>>
    IntReversePrioQueue; // A->Z

void solve(void) {
  int N;
  cin >> N;
  vector<string> ss;
  vector<int> ns;
  rep(N, i) {
    string s;
    cin >> s;
    ss.pb(s);
  }
  rep(N - 1, i) Rep(i + 1, N - 1, j) {
    ns.pb(stoi(ss[i] + ss[j]));
    ns.pb(stoi(ss[j] + ss[i]));
  }
  sort(all(ns));
  printf("%d\\n", ns[2]);
}

int main(void) {
  solve();
  return 0;
}
Problem p00507 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

typedef long long ll;
#define REP(i, n) for (long long int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  int n, tmp;
  cin >> n;
  vector<int> v;
  REP(i, n) {
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(), v.end());
  priority_queue<int, vector<int>, greater<int>> ans;
  REP(i, min(n, 10)) {
    REP(j, min(n, 10)) {
      if (j == i)
        continue;
      ans.push(stoi(to_string(v[i]) + to_string(v[j])));
    }
  }
  ans.pop();
  ans.pop();
  cout << ans.top() << endl;

  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

typedef long long ll;
#define REP(i, n) for (long long int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  int n, tmp;
  cin >> n;
  vector<int> v;
  REP(i, n) {
    cin >> tmp;
    v.push_back(tmp);
  }
  priority_queue<int, vector<int>, greater<int>> ans;
  REP(i, n) {
    REP(j, n) {
      if (j == i)
        continue;
      ans.push(stoi(to_string(v[i]) + to_string(v[j])));
    }
  }
  ans.pop();
  ans.pop();
  cout << ans.top() << endl;

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>

using namespace std;
typedef long long ll;
int n;
string str[60];
vector<string> ss;
vector<ll> kk;

int main(void) {
  scanf("%d", &n);
  priority_queue<int> que;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    que.push(a);
    if (que.size() >= 5)
      que.pop();
  }
  for (int i = min(3, n - 1); i >= 0; i--) {
    int b = que.top();
    que.pop();
    stringstream sss;
    sss << b;
    sss >> str[i];
  }
  for (int i = 0; i <= min(3, n - 1); i++) {
    for (int j = 0; j <= min(3, n - 1); j++) {
      if (i == j)
        continue;
      string sss;
      sss = str[i];
      sss += str[j];
      stringstream ssss;
      ssss << sss;
      ll co;
      ssss >> co;
      kk.push_back(co);
    }
  }
  sort(kk.begin(), kk.end());
  cout << kk[2] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

int n;
string str[6];
vector<string> ss;

int main(void) {
  scanf("%d", &n);
  priority_queue<int> que;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    que.push(a);
    if (que.size() >= 5)
      que.pop();
  }
  for (int i = min(4, n - 1); i >= 0; i--) {
    int b = que.top();
    que.pop();
    stringstream sss;
    sss << b;
    sss >> str[i];
  }
  for (int i = 0; i <= min(4, n - 1); i++) {
    for (int j = 0; j <= min(4, n - 1); j++) {
      if (i == j)
        continue;
      string sss;
      sss = str[i];
      sss += str[j];
      ss.push_back(sss);
    }
  }
  sort(ss.begin(), ss.end());
  cout << ss[2] << endl;
  return 0;
}