QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90036 | #5481. Beast Bullies | EasyJudge | WA | 175ms | 5284kb | C++23 | 1.1kb | 2023-03-22 02:48:27 | 2023-03-22 02:48:29 |
Judging History
answer
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
// create an array to store the strengths of the animals
int strengths[n];
for (int i = 0; i < n; i++) {
cin >> strengths[i];
}
// sort the strengths in decreasing order
sort(strengths, strengths + n, greater<int>());
// keep track of the sum of the strengths of the animals
int sum = 0;
for (int i = 0; i < n; i++) {
// get the strength of the weakest animal
int weakest = strengths[i];
// calculate the sum of the strengths of the attackers and defenders
int attackers = sum;
int defenders = weakest;
// check if the weakest animal should leave
if (attackers > defenders) {
// the weakest animal should leave
break;
}
// the weakest animal should stay
sum += weakest;
}
// output the number of animals remaining
cout << n - (int)(strengths + n - upper_bound(strengths, strengths + n, sum)) << endl;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 175ms
memory: 5284kb
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:
500000
result:
wrong answer 1st lines differ - expected: '155101', found: '500000'