116502024-11-03 17:00:11MagyarKendeSZLGMaximális szorzat (50 pont)cpp17Wrong answer 6/5078ms3752 KiB
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    ll N, K, B;
    cin >> N >> K >> B;

    vector<ll> neg, pos;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        if (x < 0) {
            neg.push_back(x);
        } else {
            pos.push_back(x);
        }
    }

    if (neg.size() < B) {
        cout << "-1\n";
        exit(0);
    }

    sort(neg.rbegin(), neg.rend());
    ll result = 1;
    for (int i = 0; i < B; i++) {
        result *= neg.back();
        neg.pop_back();
    }

    priority_queue<ll, vector<ll>, greater<ll>> pq;
    for (int i = 0; i < pos.size(); i++) {
        pq.push(pos[i]);
    }
    for (int i = 0; i < neg.size(); i++) {
        pq.push(neg[i]);
    }

    for (int i = 0; i < K; i++) {
        int mn = pq.top();
        pq.pop();
        pq.push(mn + 1);
    }

    while (!pq.empty()) {
        int mn = pq.top();
        if (mn < 0) {
            cout << "-1\n";
            exit(0);
        }
        pq.pop();
        result *= mn;
    }

    cout << result << "\n";
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/01ms320 KiB
2Accepted0/01ms320 KiB
3Accepted0/01ms508 KiB
4Accepted0/01ms320 KiB
5Wrong answer0/04ms672 KiB
6Wrong answer0/21ms320 KiB
7Wrong answer0/21ms320 KiB
8Wrong answer0/21ms320 KiB
9Wrong answer0/22ms508 KiB
10Wrong answer0/27ms568 KiB
11Wrong answer0/271ms3496 KiB
12Wrong answer0/178ms3628 KiB
13Wrong answer0/12ms320 KiB
14Wrong answer0/17ms472 KiB
15Accepted1/129ms1468 KiB
16Wrong answer0/137ms1536 KiB
17Accepted1/130ms1204 KiB
18Accepted1/112ms1560 KiB
19Runtime error0/145ms1900 KiB
20Runtime error0/132ms1712 KiB
21Runtime error0/163ms2320 KiB
22Runtime error0/126ms1688 KiB
23Wrong answer0/176ms2884 KiB
24Wrong answer0/178ms3752 KiB
25Wrong answer0/21ms508 KiB
26Wrong answer0/26ms672 KiB
27Runtime error0/232ms1464 KiB
28Runtime error0/130ms1464 KiB
29Accepted2/223ms1292 KiB
30Wrong answer0/163ms2224 KiB
31Accepted1/139ms3248 KiB
32Wrong answer0/22ms500 KiB
33Wrong answer0/264ms2240 KiB
34Wrong answer0/164ms2300 KiB
35Wrong answer0/267ms2224 KiB
36Wrong answer0/263ms2220 KiB
37Wrong answer0/263ms2224 KiB
38Wrong answer0/263ms2364 KiB
39Wrong answer0/12ms500 KiB