116532024-11-03 17:15:55MagyarKendeSZLGMaximális szorzat (50 pont)cpp17Wrong answer 43/5079ms2804 KiB
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

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();
        result %= MOD;
        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;
            result %= MOD;
        }
    }

    cout << result << "\n";
}

SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms500 KiB
2Accepted0/01ms320 KiB
3Accepted0/01ms320 KiB
4Accepted0/01ms320 KiB
5Accepted0/04ms516 KiB
6Accepted2/21ms320 KiB
7Accepted2/21ms320 KiB
8Accepted2/21ms332 KiB
9Accepted2/21ms320 KiB
10Accepted2/27ms704 KiB
11Accepted2/272ms2732 KiB
12Accepted1/179ms2700 KiB
13Accepted1/12ms320 KiB
14Accepted1/17ms568 KiB
15Accepted1/130ms1028 KiB
16Accepted1/139ms1072 KiB
17Accepted1/132ms1020 KiB
18Accepted1/112ms1456 KiB
19Wrong answer0/143ms1464 KiB
20Wrong answer0/132ms1492 KiB
21Wrong answer0/161ms1548 KiB
22Wrong answer0/126ms1456 KiB
23Accepted1/176ms1824 KiB
24Accepted1/179ms2804 KiB
25Accepted2/21ms320 KiB
26Accepted2/26ms568 KiB
27Wrong answer0/230ms1032 KiB
28Wrong answer0/130ms948 KiB
29Accepted2/219ms948 KiB
30Accepted1/163ms1464 KiB
31Accepted1/137ms2732 KiB
32Accepted2/22ms320 KiB
33Accepted2/264ms1456 KiB
34Accepted1/164ms1336 KiB
35Accepted2/267ms1456 KiB
36Accepted2/263ms1452 KiB
37Accepted2/263ms1456 KiB
38Accepted2/263ms1552 KiB
39Accepted1/12ms508 KiB