alexjercan/bugnet huggingface dataset:
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#pragma GCC optimize("O2")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
static inline int IN(void) {
  int x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
static inline void Radix(int A[], const int N) {
  int temp[200001];
  rep(k, 4) {
    int u[256] = {}, v[256] = {};
    rep(i, N) u[A[i] >> 8 * k & 255]++;
    rep(i, 255) u[i + 1] += u[i];
    rep(i, N) { temp[--u[A[N - 1 - i] >> 8 * k & 255]] = A[N - 1 - i]; }
    k++;
    rep(i, N) v[temp[i] >> 8 * k & 255]++;
    rep(i, 255) v[i + 1] += v[i];
    rep(i, N) A[--v[temp[N - 1 - i] >> 8 * k & 255]] = temp[N - 1 - i];
  }
}
int main() {
  int i = 0, N = IN(), A[200000];
  long sum = 0;
  while (i < N) {
    A[i++] = IN();
  }
  Radix(A, N);
  i = 1;
  while (i < N) {
    sum += A[N - 1 - i++ / 2];
  }
  return printf("%ld\\n", sum), 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#pragma GCC optimize("O2")
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define swap(a, b) ((a != b) && (a += b, b = a - b, a -= b))
static inline int IN(void) {
  int x = 0, f = 0, c = getchar();
  while (c < 48 || c > 57) {
    f ^= c == 45, c = getchar();
  }
  while (c > 47 && c < 58) {
    x = x * 10 + c - 48, c = getchar();
  }
  return f ? -x : x;
}
int BFPRT(int *v, int n, int k) {
  if (n == 1 && k == 0)
    return v[0];
  int m = (n + 4) / 5, *medians = (int *)malloc(sizeof(int) * m), temp;
  rep(i, m) {
    if (5 * i + 4 < n) {
      int *w = v + 5 * i;
      rep(j, 3) {
        temp = j;
        rep(k, j + 6) {
          if (w[j + 1 + k] < w[temp])
            temp = j + 1 + k;
        }
        swap(w[j], w[temp]);
      }
      medians[i] = w[2];
    } else {
      medians[i] = v[5 * i];
    }
  }
  int pivot = BFPRT(medians, m, m / 2);
  free(medians);
  rep(i, n) {
    if (v[i] == pivot) {
      swap(v[i], v[n - 1]);
      break;
    }
  }
  int store = 0;
  rep(i, n - 1) {
    if (v[i] < pivot) {
      swap(v[i], v[store++]);
    }
  }
  swap(v[store], v[n - 1]);
  if (store == k) {
    return pivot;
  } else if (store > k) {
    return BFPRT(v, store, k);
  } else {
    return BFPRT(v + store + 1, n - store - 1, k - store - 1);
  }
}
int main() {
  int i = 0, N = IN(), A[200000], m = 2e9;
  long sum = 0;
  while (i < N) {
    A[i++] = IN();
    m = m < A[i - 1] ? m : A[i - 1];
    sum += BFPRT(A, i, i / 2);
  }
  return printf("%ld\\n", sum - m), 0;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;
int main() {
  int n, A[200000];
  scanf("%i", &n);
  for (int i = 0; i < n; i++) {
    scanf("%i", A + i);
  }
  sort(A, A + n, greater<int>());
  long long ans = A[0];
  n -= 2;
  for (int i = 1; n; i++) {
    if (n == 1) {
      ans += A[i];
      n = 0;
    } else {
      ans += A[i] << 1ll;
      n -= 2;
    }
  }
  printf("%lli", ans);
}


Error: WA

Fixed submission:

#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;
int main() {
  int n, A[100000];
  scanf("%i", &n);
  for (int i = 0; i < n; i++) {
    scanf("%i", A + i);
  }
  sort(A, A + n, greater<int>());
  long long ans = A[0];
  n -= 2;
  for (int i = 1; n; i++) {
    if (n == 1) {
      ans += A[i];
      n = 0;
    } else {
      ans += A[i] << 1ll;
      n -= 2;
    }
  }
  printf("%lli", ans);
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

/* Author: topcoderme123
   Date: 5th july
*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define np next_permutation
using namespace std;
using vi = vector<int>;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int, int>
#define vl vector<ll>
#define vs vector<string>
#define us unordered_map<int, int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int, vi, greater<int>>
#define eb emplace_back
#define prl pair<ll, ll>
#define vp vector<pr>
#define inf 1000000000000000008
#define ld long double
const ll N = 2e5 + 23;

ll n, sum, j;

ll a[N];
unordered_map<ll, ll> dp;

void solve() {
  cin >> n;
  lp(i, n) cin >> a[i], dp[a[i]] = 1;
  sort(a, a + n, greater<int>());

  lps(i, 1, n) {
    if (i == 1)
      sum += a[j++], dp[a[i]] <<= 1;
    else {
      sum += a[j];
      if (dp[a[i]] != N)
        dp[a[i]] = min(N, dp[a[i]] * 2);
      dp[a[j]]--;
      while (!dp[a[j]] and j < n)
        j++;
    }
  }
  cout << sum << "\\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);

  // assert(freopen("input.txt", "r", stdin));
  // assert(freopen("output.txt", "w", stdout));

  solve();
  return 0;
}


Error: 0

Fixed submission:

/* Author: topcoderme123
   Date: 5th july
*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define np next_permutation
using namespace std;
using vi = vector<int>;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int, int>
#define vl vector<ll>
#define vs vector<string>
#define us unordered_map<int, int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int, vi, greater<int>>
#define eb emplace_back
#define prl pair<ll, ll>
#define vp vector<pr>
#define inf 1000000000000000008
#define ld long double
const ll N = 2e5 + 23;

ll n, sum, j;

ll a[N], dp[N + 6];

void solve() {
  cin >> n;
  lp(i, n) cin >> a[i], dp[a[i]] = 1;
  sort(a, a + n, greater<int>());

  lps(i, 1, n) {
    if (i == 1)
      sum += a[j++], dp[a[i]] <<= 1;
    else {
      sum += a[j];
      if (dp[a[i]] != N)
        dp[a[i]] = min(N, dp[a[i]] * 2);
      dp[a[j]]--;
      while (!dp[a[j]] and j < n)
        j++;
    }
  }
  cout << sum << "\\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);

  // assert(freopen("input.txt", "r", stdin));
  // assert(freopen("output.txt", "w", stdout));

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

/* Author: topcoderme123
   Date: 5th july
*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define np next_permutation
using namespace std;
using vi = vector<int>;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int, int>
#define vl vector<ll>
#define vs vector<string>
#define us unordered_map<int, int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int, vi, greater<int>>
#define eb emplace_back
#define prl pair<ll, ll>
#define vp vector<pr>
#define inf 1000000000000000008
#define ld long double
const ll N = 2e5 + 23;

ll n, sum, j;

ll a[N];
map<ll, ll> dp;

void solve() {
  cin >> n;
  lp(i, n) cin >> a[i], dp[a[i]] = 1;
  sort(a, a + n, greater<int>());

  lps(i, 1, n) {
    if (i == 1)
      sum += a[j++], dp[a[i]] <<= 1;
    else {
      sum += a[j];
      if (dp[a[i]] != N)
        dp[a[i]] = min(N, dp[a[i]] * 2);
      dp[a[j]]--;
      while (!dp[a[j]] and j < n)
        j++;
    }
  }
  cout << sum << "\\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);

  // assert(freopen("input.txt", "r", stdin));
  // assert(freopen("output.txt", "w", stdout));

  solve();
  return 0;
}


Error: 0

Fixed submission:

/* Author: topcoderme123
   Date: 5th july
*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define np next_permutation
using namespace std;
using vi = vector<int>;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lps(i, j, n) for (int i = j; i < n; i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int, int>
#define vl vector<ll>
#define vs vector<string>
#define us unordered_map<int, int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int, vi, greater<int>>
#define eb emplace_back
#define prl pair<ll, ll>
#define vp vector<pr>
#define inf 1000000000000000008
#define ld long double
const int N = 2e5 + 23;

ll n, sum, j;

ll a[N], dp[N];

void solve() {
  cin >> n;
  lp(i, n) cin >> a[i], dp[a[i]] = 1;
  sort(a, a + n, greater<int>());

  lps(i, 1, n) {
    if (i == 1)
      sum += a[j++], dp[a[i]] <<= 1;
    else {
      sum += a[j];
      dp[a[i]] <<= 1;
      dp[a[j]]--;
      while (!dp[a[j]] and j < n)
        j++;
    }
  }
  cout << sum << "\\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);

  // assert(freopen("input.txt", "r", stdin));
  // assert(freopen("output.txt", "w", stdout));

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

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define gcda(x, y) gcd(abs(x), abs(y))

#define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll, ll>;

template <typename T> inline istream &operator>>(istream &i, vector<T> &v) {
  REP(j, sz(v)) i >> v[j];
  return i;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  ll ans = 0;

  deque<ll> com;
  com.push_back(a[0]);

  for (int i = 1; i < n; i++) {
    int x = a[i];
    ans += com[0];
    com.push_back(x);
    com.push_back(x);
    com.pop_front();
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a, b) make_pair((a), (b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)

#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define gcda(x, y) gcd(abs(x), abs(y))

#define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll, ll>;

template <typename T> inline istream &operator>>(istream &i, vector<T> &v) {
  REP(j, sz(v)) i >> v[j];
  return i;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  ll ans = 0;

  vector<ll> com;
  com.push_back(a[0]);

  for (int i = 1; i < n; i++) {
    int x = a[i];
    ans += com[0];
    com.push_back(x);
    com.push_back(x);
    com.erase(com.begin());
  }

  cout << ans << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

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

int N;
int A[200001];

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

  sort(A, A + N, greater<int>());

  long long ans = 0;
  for (int i = 1; i < N; i++) {
    ans += A[i / 2];
  }

  cout << ans;
}

Error: WA

Fixed submission:

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

int N;
int A[20000];

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

  sort(A, A + N, greater<int>());

  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans += A[i];
    if (i > 0 && N - 2 - i > 1) {
      ans += A[i];
      i += 1;
    }
  }

  cout << ans;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0)->sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());

  ll res = a[0];
  int cnt = 1;
  int i = 1;
  while (true) {
    if (cnt == n - 1)
      break;
    res += a[i];
    cnt++;
    if (cnt == n - 1)
      break;
    res += a[i];
    cnt++;
    i++;
  }
  cout << res << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0)->sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());

  ll res = a[0];
  int cnt = 1;
  int i = 1;
  while (true) {
    res += a[i];
    cnt++;
    if (cnt == n - 1)
      break;
    res += a[i];
    cnt++;
    if (cnt == n - 1)
      break;
    i++;
  }
  cout << res << '\\n';
  return 0;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long long int a[200007];
int main() {
  long long int n, i, j, k, ans = 0, count = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  if (n >= 3) {
    sort(a, a + n);
    for (i = n - 2; i > 0; i--) {
      ans += a[i];
      count++;
      if (count == n - 2)
        break;
      ans += a[i];
      count++;
      if (count == n - 2)
        break;
    }
    cout << ans + a[n - 1] << "\\n";
  } else {

    sort(a, a + n);
    if (n == 1)
      cout << 0 << "\\n";
    else
      cout << a[1] << "\\n";
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int a[200007];
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, i, j, k, ans = 0, count = 0;
    cin >> n;
    for (i = 0; i < n; i++)
      cin >> a[i];
    if (n >= 3) {
      sort(a, a + n);
      for (i = n - 2; i >= 0; i--) {
        ans += a[i];
        count++;
        if (count == n - 2)
          break;
        ans += a[i];
        count++;
        if (count == n - 2)
          break;
      }
      cout << ans + a[n - 1] << "\\n";
    } else {

      sort(a, a + n);
      if (n == 1)
        cout << 0 << "\\n";
      else
        cout << a[1] << "\\n";
    }
  }
}
Problem p02615 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n, 2);
  b[0] = 1;
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end(), greater<int>());

  if (n == 2) {
    cout << a[0] << endl;
    return 0;
  }

  ll ans = 0;
  int c = 0;
  rep(i, n - 1) {
    ans += a[c];
    b[c]--;
    if (b[c] <= 0)
      c++;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n, 2);
  b[0] = 1;
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end(), greater<int>());

  if (n == 2) {
    cout << a[0] << endl;
    return 0;
  }

  ll ans = 0;
  rep(i, n - 1) rep(j, n) {
    if (b[j] > 0) {
      ans += a[j];
      b[j]--;
      break;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> a;
  a.push_back(0); // ダミーデータ
  ll in;
  rep(i, n) {
    cin >> in;
    a.push_back(in);
  }

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

  ll ans = 0;
  for (int k = 1; k <= n - 1; k++) {
    ans += a[n - k / 2];
  }

  cout << ans << endl;

  return (0);
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  priority_queue<ll> pq;
  vector<ll> vec;
  ll input;
  for (int i = 0; i < n; i++) {
    cin >> input;
    pq.push(input);
  }

  ll ans = pq.top();
  vec.push_back(pq.top());
  vec.push_back(pq.top());
  pq.pop();
  vec.insert(vec.begin() + 1, pq.top());
  pq.pop();

  while (!pq.empty()) {
    ll tmp = pq.top();
    pq.pop();
    ll m = 0;
    int idx = 1;
    for (int i = 1; i < vec.size(); i++) {
      if (m < min(vec[i - 1], vec[i])) {
        m = min(vec[i - 1], vec[i]);
        idx = i;
      }
    }

    ans += m;
    vec.insert(vec.begin() + idx, tmp);
  }

  cout << ans << endl;
  /*
  for (int i = 0;i < vec.size();i++) {
      cout << "vec:" << vec[i] << endl;
  }
  */

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

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

int main() {
  long long n;
  cin >> n;
  vector<long long> v;
  long long sum = 0;

  for (long long i = 0; i < n; i++) {
    long long c;
    cin >> c;
    v.push_back(c);
  }

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

  for (int i = 0; i < n - 1; i++) {
    int s = (i + 1) / 2;

    sum += v[n - 1 - s];
  }

  cout << sum << endl;
}


Error: 0

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  long long a[n];
  long long minimum = pow(10, 10);
  long long sum = 0;

  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    minimum = min(minimum, a[i]);
    sum += a[i];
  }

  long long ans = sum - minimum;

  cout << ans << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;

  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }

  // クイックソートがO(N logN)
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  ll ans = 0;
  queue<ll> q;
  // 一人目が到着
  // 一人目の心地よさを享受可能な座席は1つのみのため、キューに1座席追加
  q.push(v.at(0));
  for (int i = 1; i < n; i++) {
    // 1人到着したため、座席を1つ消費する
    ans += q.front();
    q.pop();

    // 二人目以降が到着すると、両隣に座席ができる
    // 心地よさは二座席分享受できるため、キューに2座席分追加
    ll num = v.at(i);
    q.push(num);
    q.push(num);
  }

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


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 1) >= this->size() (which is 1)


Fixed submission:

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

int main() {
  int H, W, K;
  cin >> H >> W >> K;

  vector<string> v(H);
  for (int i = 0; i < H; i++) {
    cin >> v.at(i);
  }

  // ビット全探索
  // 入力例1の場合は、2^2 * 2^3 = 32パターンの全探索となる
  // (H, W) = (00, 000) ~ (11, 111)
  int ans = 0;
  for (int h = 0; h < (1 << H); h++) {
    for (int w = 0; w < (1 << W); w++) {

      // 各パターンについて '#' 記号の数を数える
      int count = 0;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          // 1の場合、# が塗り替えられているとする
          if (((h >> i) & 1) == 0 && ((w >> j) & 1) == 0 &&
              v.at(i).at(j) == '#') {
            count++;
          }
        }
      }

      if (count == K) {
        ans++;
      }
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #include "atcoder/all"

using namespace std;
// using namespace atcoder;

#define ll long long int
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define P pair<int, int>

int mx8[] = {0, 0, 1, -1, -1, 1, -1, 1};
int my8[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int mx4[] = {1, -1, 0, 0};
int my4[] = {0, 0, -1, 1};
const int MOD = 1000000007;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll ans = 0;
  rep(i, n) { ans += a[i / 2]; }
  cout << ans - a[0] << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define ll long long int
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int mx4[] = {0, 1, 0, -1};
int my4[] = {1, 0, -1, 0};
ll MOD = 1e9 + 7;

char r[26], l[26];

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), c, b, d;
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());

  ll cnt = 0, ans = 0;
  rep(i, n - 1) {
    if (a[i] == a[i + 1])
      cnt++;
    else {
      c.pb(cnt);
      b.pb(a[i]);
      d.pb(cnt);
    }
  }
  if (cnt) {
    b.pb(a[n - 1]);
    c.pb(cnt);
    d.pb(cnt);
  }
  rep(i, c.size() - 1) c[i] += c[i + 1];

  ll i = 0, j = 0, k = n - 1;
  while (i < n - 1) {
    ans += min(c[j], k) * b[j];
    i += c[j];
    j++;
    k -= d[j];
  }
  cout << ans << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<ll> A;
  priority_queue<ll> A_queue;
  for (int i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    A.push_back(a);
  }

  sort(A.begin(), A.end());
  ll ans = 0;
  while (A.size() > 0) {
    ll max = A.back();
    A.pop_back();
    if (A_queue.empty()) {
      A_queue.push(max);
      continue;
    }

    ans += A_queue.top();
    A_queue.pop();
    A_queue.push(max);
    A_queue.push(max);
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

#define ll long long

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<ll> A;
  for (int i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    A.push_back(a);
  }

  ll ans = 0;
  vector<ll> nums;
  sort(A.begin(), A.end());
  while (A.size() > 0) {
    ll max = A.back();
    A.pop_back();
    if (nums.size() == 0) {
      nums.push_back(max);
      continue;
    }

    decltype(nums)::iterator max_itr = max_element(nums.begin(), nums.end());
    ans += *max_itr;
    nums.erase(max_itr);
    nums.push_back(max);
    nums.push_back(max);
  }

  cout << ans << endl;
}
Problem p02615 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  long int N, a[200000], count = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N, greater<int>());
  for (int j = 0; j < N; j++) {
    count += a[j / 2];
  }
  count -= a[0];
  cout << count << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  long int N, a[100000], count = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N, greater<int>());
  for (int j = 0; j < N; j++) {
    count += a[j / 2];
  }
  count -= a[0];
  cout << count << endl;
  return 0;
}