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

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
  unsigned int n;
  while (scanf("%d", &n), n) {
    unsigned int gp = 0;
    for (unsigned int i = 0; i < n; i++) {
      unsigned int x;
      scanf("%d", &x);
      gp += x;
    }
    vector<unsigned int> j(n - 1);

    for (unsigned int i = 0; i < n - 1; i++) {
      scanf("%d", &j[i]);
    }

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

    unsigned int ans = gp * n;

    for (unsigned int i = n - 1; i > 0; i--) {

      gp += j[i - 1];
      ans = max(ans, gp * i);
    }

    printf("%u\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  unsigned int n;
  while (scanf("%d", &n), n) {
    unsigned int p[10000] = {0};
    unsigned int y = 0;
    unsigned int ans = 0;
    for (unsigned int i = 0; i < n; i++) {
      cin >> p[i];
      y += p[i];
    }

    unsigned int j[10000] = {0};
    for (unsigned int i = 0; i < n - 1; i++) {
      cin >> j[i];
    }
    sort(j, j + n - 1);

    ans = y * n;
    for (unsigned int i = n - 1; i > 0; i--) {
      y += j[i - 1];
      ans = max(ans, y * i);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
using namespace std;
long long b[65000], m, w;
int main(void) {
  int n, i, a;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    w = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a);
      w += a;
    }
    for (i = 1; i < n; i++) {
      scanf("%lld", &b[i]);
    }
    sort(b + 1, b + n);
    m = w * n;
    for (i = n - 1; i > 0; i--) {
      w = w + b[i];
      if (m < w * i) {
        m = w * i;
      }
    }
    printf("%lld\\n", m);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, a[65000], b[65000], c[30000], w, j, i, flg, kyu;
  scanf("%d", &n);
  while (n != 0) {
    kyu = 0;
    for (i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
      kyu = kyu + a[i];
    }
    kyu = kyu * n;
    for (i = 0; i < n - 1; i++) {
      scanf("%lld", &b[i]);
    }
    for (i = 0; i < n - 2; i++) {
      for (j = i + 1; j < n - 1; j++) {
        if (b[i] < b[j]) {
          w = b[i];
          b[i] = b[j];
          b[j] = w;
        }
      }
    }
    for (i = 0; i < 30000; i++)
      c[i] = 0;
    j = 0;
    flg = 0;
    while (1) {
      for (i = n - 1; i >= 0; i--) {
        if (flg == 0) {
          c[j] = c[j] + (a[i] + b[j] + a[i - 1]);
          i--;
          a[n - 2] = c[j];
          flg = 1;
        } else if (flg == 1) {
          c[j] = c[j] + a[i];
        }
      }
      n--;
      if (kyu < c[j] * n) {
        kyu = c[j] * n;
      }
      j++;
      if (n == 1)
        break;
    }
    printf("%lld\\n", kyu);
    scanf("%lld", &n);
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i <= k; i++)
#define in(i, j, k) ((i) >= (j) && (i) <= (k))

long long n, p, j[65000], s, a;
int main() {
  for (;;) {
    scanf("%lld", &n);
    if (n == 0)
      break;
    s = a = 0;
    rep(i, n) {
      scanf("%lld", &p);
      s += p;
    }
    rep(i, n - 1) scanf("%lld", j + i);
    sort(j, j + n - 1);
    rep(i, n) {
      a = max((n - i) * s, a);
      if (i != n - 1)
        s += j[n - i - 2];
    }
    printf("%lld\\n", a);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) for (int i = 0; i < (j); i++)

int main() {
  long long n, p, j[65000], s, a;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    s = a = 0;
    rep(i, n) {
      scanf("%d", &p);
      s += p;
    }
    rep(i, n - 1) scanf("%d", j + i);
    sort(j, j + n - 1);
    rep(i, n) {
      a = max((n - i) * s, a);
      if (i != n - 1)
        s += j[n - i - 2];
    }
    printf("%d\\n", a);
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long int p[100000], j[100000];
int main(void) {
  long long int n, sum, sum1, max, cnt, i;
  while (1) {
    scanf("%lld", &n);
    if (n == 0)
      break;
    sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%lld", &p[i]);
      sum += p[i];
    }
    cnt = n;
    max = sum * cnt;
    for (i = 0; i < n - 1; i++) {
      scanf("%lld", &j[i]);
      j[i] *= -1;
    }
    sort(j, j + n);
    for (i = 0; i < n - 1; i++)
      j[i] *= -1;
    for (i = 0; i < n - 1; i++) {
      cnt--;
      sum += j[i];
      sum1 = sum * cnt;
      if (max < sum1)
        max = sum1;
      //	printf("%d\\n",sum1);
    }
    printf("%lld\\n", max);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, p[1001], j[1001], sum, sum1, max, cnt, i;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &p[i]);
      sum += p[i];
    }
    cnt = n;
    max = sum * cnt;
    for (i = 0; i < n - 1; i++) {
      scanf("%d", &j[i]);
      j[i] *= -1;
    }
    sort(j, j + n);
    for (i = 0; i < n - 1; i++)
      j[i] *= -1;
    for (i = 0; i < n - 1; i++) {
      cnt--;
      sum += j[i];
      sum1 = sum * cnt;
      if (max < sum1)
        max = sum1;
      //	printf("%d\\n",sum1);
    }
    printf("%d\\n", max);
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

// 2012 toi5 start 13:15
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <vector>
// #include<conio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <string.h>
using namespace std;

int main() {

  long long n, i, t, sump = 0, sumj = 0, maxv = 0, v = 0;
  int p[100000], j[100000];
  while (cin >> n, n) {
    memset(p, 0, sizeof(p));
    memset(j, 0, sizeof(j));
    for (i = 0; i < n; i++) {
      cin >> p[i];
      sump += p[i];
    }
    for (i = 0; i < n - 1; i++) {
      cin >> j[i];
    }
    sort(j, j + (n - 1), greater<int>());
    for (i = 0, t = n; t >= 1;
         t--, i++) { //??????????????¬??°????????§??????????????¬??°???
      maxv = t * (sump + sumj);
      sumj += j[i];
      v = max(v, maxv);
    }
    cout << v << endl;
    sump = 0, sumj = 0, maxv = 0, v = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <list>
#include <map>
#include <queue>
#include <stack>
#include <vector>
// #include<conio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <string.h>
using namespace std;
int main() {

  long long n, i, t, sump = 0, sumj = 0, maxv = 0, v = 0;
  while (cin >> n, n) {
    long long p[1001], j[1001];
    for (i = 0; i < n; i++) {
      cin >> p[i];
      sump += p[i];
    }
    for (i = 0; i < n - 1; i++) {
      cin >> j[i];
    }
    maxv = sump * n;
    sort(j, j + n, greater<int>());
    for (i = 0, t = n - 1; t >= 1;
         t--, i++) { //??????????????¬??°????????§??????????????¬??°???
      v += j[i];
      maxv = max(t * (sump + v), maxv);
      // cout << t*(sump + v) << "  " << maxv << endl;
    }
    cout << maxv << endl;
    sump = 0, sumj = 0, maxv = 0, v = 0;
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
using namespace std;
bool value(int y, int x, int R, int C) {
  return 0 <= y && y < R && 0 <= x && x < C;
}
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<unsigned int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;
double pie = acos(-1);
int INF = 10000009;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  unsigned int n;
  unsigned int p[65005];
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    vi j(n);
    unsigned int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      sum += p[i];
    }
    unsigned int ans = sum * n;
    for (int i = 0; i < n - 1; i++) {
      cin >> j[i];
    }
    sort(j.begin(), j.end());
    reverse(j.begin(), j.end());
    vi l(n);
    l[0] = sum;
    for (int i = 1; i < n; i++) {
      l[i] = l[i - 1] + j[i - 1];
    }

    for (int i = 0; i < n; i++) {
      unsigned int x = n - i;
      unsigned int y = l[i];
      ans = max(ans, x * y);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
using namespace std;
bool value(int y, int x, int R, int C) {
  return 0 <= y && y < R && 0 <= x && x < C;
}
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;
double pie = acos(-1);
int INF = 10000009;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  int n;
  int p[65005];
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    vi j(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      sum += p[i];
    }
    int ans = sum * n;
    // cout<<ans<<endl;
    for (int i = 0; i < n - 1; i++) {
      cin >> j[i];
    }
    sort(j.begin(), j.end());
    reverse(j.begin(), j.end());
    for (int i = 0; i < n; i++) {
      int x = n - i;
      int y = sum;
      for (int k = 0; k < i; k++) {
        y += j[k];
      }
      ans = max(ans, x * y);
    }
    cout << ans << endl;
  }
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <functional>
#define max jgslkgjsojgps
using namespace std;
int main(void) {
  long long int n, p, j[70000], sum, x, i, k, max;
  while (1) {
    scanf("%lld", &n);
    if (n == 0)
      break;
    sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%lld", &p);
      sum += p;
    }
    for (i = 0; i < n - 1; i++) {
      scanf("%lld", &j[i]);
    }
    sort(j, j + n - 1, greater<int>());
    max = 0;
    for (i = 0; i < n; i++) {
      if (max < (n - i) * sum)
        max = (n - i) * sum;
      else
        break;
      sum += j[i];
    }
    printf("%lld\\n", max);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  long long int n, p, j[70000], sum, x, i, k, max;
  while (1) {
    scanf("%lld", &n);
    if (n == 0)
      break;
    sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%lld", &p);
      sum += p;
    }
    for (i = 0; i < n - 1; i++) {
      scanf("%lld", &j[i]);
      //	printf("i=%d\\n",i);
    }
    for (i = 0; i < n - 2; i++) {
      for (k = i + 1; k < n - 1; k++) {
        if (j[i] < j[k]) {
          x = j[i];
          j[i] = j[k];
          j[k] = x;
        }
      }
    }

    max = 0;
    for (i = 0; i < n; i++) {
      if (max < (n - i) * sum)
        max = (n - i) * sum;
      else
        break;
      sum += j[i];
    }
    printf("%d\\n", max);
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i, f, n) for (int i = f; i < int(n); ++i)
#define rep(i, n) reps(i, 0, n)

ll func(ll n) {
  ll L = 0;
  rep(i, n) {
    int p;
    cin >> p;
    L += p;
  }

  vi j(n - 1);
  rep(i, n - 1) { cin >> j[i]; }
  sort(j.rbegin(), j.rend());

  ll ans = n * L;
  for (int l : j) {
    if (n * l > L + 1) {
      L += l;
      --n;
      ans = max(ans, n * L);
    } else {
      break;
    }
  }

  return ans;
}

int main() {
  int n;
  while (cin >> n, n) {
    cout << func(n) << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i, f, n) for (int i = f; i < int(n); ++i)
#define rep(i, n) reps(i, 0, n)

ll func(int n) {
  ll L = 0;
  rep(i, n) {
    int p;
    cin >> p;
    L += p;
  }

  vi j(n - 1);
  rep(i, n - 1) { cin >> j[i]; }
  sort(j.rbegin(), j.rend());

  for (int l : j) {
    if (n * l > L + 1) {
      L += l;
      --n;
    } else {
      break;
    }
  }

  return n * L;
}

int main() {
  int n;
  while (cin >> n) {
    cout << func(n) << endl;
  }
}
Problem p00255 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 65010

void calc(int n) {
  int p, sump = 0;
  int joi[SIZE];

  for (int i = 0; i < n; i++) {
    scanf("%d", &p);
    sump += p;
  }

  for (int i = 0; i < n - 1; i++) {
    scanf("%d", joi + i);
  }

  sort(joi, joi + n - 1);

  ll ans = (ll)sump * n;

  for (int i = n - 2; i >= 0; i--) {
    sump += joi[i];

    ans = max(ans, (ll)sump * (i + 1));
  }

  printf("%lld\\n", ans);
}

int main() {

  int n;

  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    calc(n);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 1000

void calc(int n) {
  int p, sump = 0;
  int joi[SIZE];

  for (int i = 0; i < n; i++) {
    scanf("%d", &p);
    sump += p;
  }

  for (int i = 0; i < n - 1; i++) {
    scanf("%d", joi + i);
  }

  sort(joi, joi + n - 1);

  ll ans = (ll)sump * n;

  for (int i = n - 2; i >= 0; i--) {
    sump += joi[i];

    ans = max(ans, (ll)sump * (i + 1));
  }

  printf("%lld\\n", ans);
}

int main() {

  int n;

  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    calc(n);
  }

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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
#define INF 1e+8
#define EPS 1e-7
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
typedef pair<int, int> Pii;
typedef vector<int> vi;
int main() {
  int n;
  while (scanf("%d", &n), n) {
    vector<ll> jo;
    ll sum = 0;
    rep(i, n) {
      int p;
      scanf("%d", &p);
      sum += (ll)p;
    }
    rep(i, n - 1) {
      ll x;
      scanf("%lld", &x);
      jo.PB(x);
    }
    ll ans = -1 * INF;
    sort(jo.begin(), jo.end());
    reverse(jo.begin(), jo.end());
    jo.PB(0);
    for (int i = n - 1; i > 0; i--) {
      jo[i] = jo[i - 1];
    }
    jo[0] = 0;
    partial_sum(jo.begin(), jo.end(), jo.begin());
    rep(i, n) {
      ll sub = sum;
      sub += jo[n - i - 1];
      sub *= (i + 1);
      ans = max(ans, sub);
    }
    printf("%lld\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
#define INF 1e+8
#define EPS 1e-7
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
typedef pair<int, int> Pii;
typedef vector<int> vi;
int main() {
  int n;
  while (scanf("%d", &n), n) {
    int p[65001];
    int jo[65000];
    int sum = 0;
    rep(i, n) {
      scanf("%d", &p[i]);
      sum += p[i];
    }
    rep(i, n - 1) { scanf("%d", &jo[i]); }
    int ans = -1 * INF;
    sort(jo, jo + n - 1);
    reverse(jo, jo + n - 1);
    rep(i, n) {
      int sub = sum;
      rep(j, n - i - 1) { sub += jo[j]; }
      sub *= (i + 1);
      // printf("sub = %d\\n",sub);
      ans = max(ans, sub);
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int P;
vector<int> J;
int main() {
  int p, j;
  long long sum, max_m;
  int N;
  while (1) {
    sum = 0;
    max_m = 0;
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> p;
      sum += p;
    }
    for (int i = 0; i < N - 1; i++) {
      cin >> j;
      J.push_back(j);
    }
    sort(J.begin(), J.end(), greater<int>());
    max_m = sum * N;
    for (int i = 1; i < N; i++) {
      max_m = max(max_m, (sum + J[i - 1]) * (N - i));
      sum += J[i - 1];
    }
    cout << max_m << endl;
    J.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n;        //??????????????¬??°
int P[65001]; //?????????
int J[65001]; //?????§?????????
int max_m;
int max_n;
int max_sum;
void OZAWA(int, int, int); // i,sum
int main() {
  while (1) {
    max_m = 0;
    max_n = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 1; i <= n; i++)
      cin >> P[i];
    for (int i = 1; i < n; i++)
      cin >> J[i];
    OZAWA(1, P[1], 1);
    cout << max_m << endl;
  }
  return 0;
}
void OZAWA(int c, int sum, int N) //????????????,????¨?,??????????????°
{
  if (c < n) {
    // cout << "A";
    OZAWA(c + 1, sum + J[c] + P[c + 1], N);
    OZAWA(c + 1, sum + P[c + 1], N + 1);
  } else {
    // cout << sum*N << endl;
    if (max_m < sum * N) {
      max_m = sum * N;
    }
  }
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <deque>
#include <iostream>
#include <vector>
using namespace std;
vector<unsigned int> p, j;
unsigned int f(unsigned int, int, unsigned int, bool);
int main(void) {
  int n;
  unsigned int money, l = 0;
  deque<int> deque;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    p.resize(n);
    j.resize(n - 1);
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      l += p[i];
    }
    for (int i = 0; i < n - 1; i++)
      cin >> j[i];
    for (int i = 0; i < n - 1; i++)
      deque.push_back(j[i]);
    sort(deque.begin(), deque.end());
    for (int i = 0; i < n - 1; i++) {
      if (1 <= i)
        j[i] = deque[n - i - 2] + j[i - 1];
      else
        j[i] = deque[n - i - 2];
    }
    deque.clear();
    money = l * n;
    for (int jn = 0; jn < n - 1; jn++)
      money = max(money, (l + j[jn]) * (unsigned int)(n - jn - 1));

    cout << money << endl;
    p.clear();
    j.clear();
    l = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <vector>
using namespace std;
vector<unsigned int> p, j;
unsigned int f(unsigned int, int, unsigned int, bool);
int main(void) {
  int n;
  unsigned int money, l = 0, dl;
  deque<int> deque;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    p.resize(n);
    j.resize(n - 1);
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      l += p[i];
    }
    for (int i = 0; i < n - 1; i++)
      cin >> j[i];
    for (int i = 0; i < n - 1; i++)
      deque.push_back(j[i]);
    sort(deque.begin(), deque.end());
    for (int i = 0; i < n - 1; i++) {
      j[n - i - 2] = deque[i];
    }
    deque.clear();
    money = l * n;
    for (int jn = 0; jn < n - 1; jn++) {
      dl = l;
      for (int djn = jn; 0 <= djn; djn--) {
        dl += j[djn];
      }
      money = max(money, dl * (unsigned int)(n - jn - 1));
    }

    cout << money << endl;
    p.clear();
    j.clear();
    l = 0;
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)

using namespace std;

int main() {
  int n, p, j[1000000];
  while (scanf("%d", &n), n) {
    long long len = 0, num = n;
    rep(i, n) {
      scanf("%d", &p);
      len += p;
    }
    rep(i, n - 1) scanf("%d", j + i);
    sort(j, j + n - 1);

    for (int i = n - 2; i >= 0; i--) {
      if ((num - 1) * (len + j[i]) < num * len)
        break;
      num--;
      len += j[i];
    }
    printf("%lld\\n", num * len);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for (int i = j; i < k; ++i)

using namespace std;

int main() {
  long long n, num, p, len, j[1024];
  while (scanf("%lld", &n), n) {
    len = 0, num = n;
    rep(i, n) {
      scanf("%lld", &p);
      len += p;
    }
    rep(i, n - 1) scanf("%lld", j + i);
    sort(j, j + n - 1);

    for (int i = n - 2; i >= 0; i--) {
      if ((num - 1) * (len + j[i]) < num * len)
        break;
      num--;
      len += j[i];
    }
    printf("%lld\\n", num * len);
  }
  return 0;
}
Problem p00255 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
using namespace std;

int main() {
  int n;
  while (cin >> n && n) {
    unsigned int p[65000], jo[65000];
    for (int i = 0; i < n; ++i)
      cin >> p[i];
    for (int i = 0; i < n - 1; ++i)
      cin >> jo[i];

    sort(jo, jo + n - 1, greater<int>());
    unsigned jsum = 0, sum = accumulate(p, p + n, 0), ans = 0;
    ans = sum * n;
    for (int i = 1; i < n; i++) {
      jsum += jo[i - 1];
      ans = max(ans, (sum + jsum) * (n - i));
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int p[1000], j[1000];
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      sum += p[i];
    }
    for (int i = 0; i < n - 1; i++) {
      cin >> j[i];
      sum += j[i];
    }

    sort(j, j + (n - 1));

    long long ans = sum;
    for (int i = 0; i < n - 1; i++) {
      sum -= j[i];
      ans = max(ans, sum * (i + 2));
    }

    cout << ans << endl;
  }
  return 0;
}