QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#90036#5481. Beast BulliesEasyJudgeWA 175ms5284kbC++231.1kb2023-03-22 02:48:272023-03-22 02:48:29

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-22 02:48:29]
  • 评测
  • 测评结果:WA
  • 用时:175ms
  • 内存:5284kb
  • [2023-03-22 02:48:27]
  • 提交

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'