QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188384#5481. Beast BulliesZiadElGafy#RE 0ms0kbC++201.5kb2023-09-25 19:47:032023-09-25 19:47:04

Judging History

你现在查看的是最新测评结果

  • [2023-09-25 19:47:04]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-09-25 19:47:03]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#define el '\n'
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef __int128 bigInt;

using namespace std;

const int N = 4e5 + 5, INF = 1e9 + 5, mod = 1e9 + 7, LOG = 21, SQ = 500;

ll n, a[N], pre[N], ps[N];

void doWork() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        pre[i] = a[i] + pre[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        int s = 1, e = i, m, ans = i;

        while (s <= e) {
            m = (s + e) >> 1;
            ll sum = pre[i] - pre[m - 1];
            if (sum >= pre[n] - pre[i]) {
                ans = m;
                s = m + 1;
            }
            else {
                e = m - 1;
            }
        }


        ps[ans] += a[i];
        ps[i + 1] -= a[i];

        if (ans > 1) {
            ps[1] += -a[i];
            ps[ans] -= -a[i];
        }
    }

    ll cur = 0, ans = n;

    for (int i = 1; i <= n; i++) {
        cur += ps[i];

        if (cur < 0) {
            ans--;
        }
        else {
            break;
        }
    }

    cout << ans << el;
}

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

    int tests = 1;
//    cin >> tests;
    for (int i = 1; i <= tests; i++) {
        doWork();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

500000
976631732
51389671
729809897
630844317
294721017
903231515
477913449
871071076
636104080
345822085
97441187
499323378
522845426
310022664
199310190
776622973
602672555
646874222
214723272
285341530
962727359
681361226
47426538
272153520
693133904
542337627
556307610
325596239
95738088
5495543...

output:


result: