QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90035#5481. Beast BulliesEasyJudgeWA 137ms5156kbC++231.1kb2023-03-22 02:46:532023-03-22 02:46:54

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:46:54]
  • 评测
  • 测评结果:WA
  • 用时:137ms
  • 内存:5156kb
  • [2023-03-22 02:46:53]
  • 提交

answer

#include <iostream>
#include <queue>
using namespace std;

int main() {
    int n;
    cin >> n;

    // create a priority queue to store the strengths of the animals
    priority_queue<int> pq;

    // read in the strengths and add them to the priority queue
    for (int i = 0; i < n; i++) {
        int strength;
        cin >> strength;
        pq.push(strength);
    }

    // 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 = pq.top();
        pq.pop();

        // calculate the sum of the strengths of the attackers and defenders
        int attackers = sum - weakest;
        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 << pq.size() << endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 137ms
memory: 5156kb

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:

499997

result:

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