116522024-11-03 17:10:41MagyarKendeSZLGMaximális szorzat (50 pont)cpp17Wrong answer 6/5076ms2732 KiB
#include <algorithm>
#include <cassert>
#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]);
    }

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

        if (pq.top() < 0) {
            cout << "-1\n";
            exit(0);
        }

        while (!pq.empty()) {
            int mn = pq.top();
            pq.pop();
            result *= mn;
        }
    }

    cout << result << "\n";
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/01ms320 KiB
2Accepted0/01ms508 KiB
3Accepted0/01ms320 KiB
4Accepted0/01ms320 KiB
5Wrong answer0/04ms648 KiB
6Wrong answer0/21ms320 KiB
7Wrong answer0/21ms512 KiB
8Wrong answer0/21ms320 KiB
9Wrong answer0/22ms496 KiB
10Wrong answer0/27ms568 KiB
11Wrong answer0/271ms2576 KiB
12Wrong answer0/176ms2728 KiB
13Wrong answer0/12ms320 KiB
14Wrong answer0/17ms452 KiB
15Accepted1/132ms1156 KiB
16Wrong answer0/139ms1080 KiB
17Accepted1/132ms948 KiB
18Accepted1/112ms1456 KiB
19Wrong answer0/143ms1444 KiB
20Wrong answer0/132ms1444 KiB
21Wrong answer0/161ms1516 KiB
22Wrong answer0/126ms1380 KiB
23Wrong answer0/175ms1856 KiB
24Wrong answer0/176ms2732 KiB
25Wrong answer0/21ms320 KiB
26Wrong answer0/26ms572 KiB
27Wrong answer0/230ms936 KiB
28Wrong answer0/130ms956 KiB
29Accepted2/218ms948 KiB
30Wrong answer0/163ms1348 KiB
31Accepted1/137ms2488 KiB
32Wrong answer0/22ms320 KiB
33Wrong answer0/263ms1452 KiB
34Wrong answer0/164ms1544 KiB
35Wrong answer0/267ms1452 KiB
36Wrong answer0/261ms1524 KiB
37Wrong answer0/261ms1552 KiB
38Wrong answer0/263ms1444 KiB
39Wrong answer0/12ms320 KiB