QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188384 | #5481. Beast Bullies | ZiadElGafy# | RE | 0ms | 0kb | C++20 | 1.5kb | 2023-09-25 19:47:03 | 2023-09-25 19:47:04 |
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...