QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188386#5481. Beast BulliesZiadElGafy#WA 72ms15360kbC++201.5kb2023-09-25 19:47:302023-09-25 19:47:31

Judging History

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

  • [2023-09-25 19:47:31]
  • 评测
  • 测评结果:WA
  • 用时:72ms
  • 内存:15360kb
  • [2023-09-25 19:47:30]
  • 提交

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 = 5e5 + 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();
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 72ms
memory: 15360kb

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:

146256

result:

wrong answer 1st lines differ - expected: '155101', found: '146256'