116542024-11-03 17:17:09MagyarKendeSZLGMaximális szorzat (50 pont)cpp17Wrong answer 43/5079ms2732 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/01ms320 KiB
2Accepted0/01ms512 KiB
3Accepted0/01ms328 KiB
4Accepted0/01ms320 KiB
5Accepted0/04ms660 KiB
6Accepted2/21ms320 KiB
7Accepted2/21ms320 KiB
8Accepted2/21ms388 KiB
9Accepted2/21ms320 KiB
10Accepted2/27ms700 KiB
11Accepted2/272ms2488 KiB
12Accepted1/178ms2732 KiB
13Accepted1/12ms320 KiB
14Accepted1/17ms620 KiB
15Accepted1/130ms1076 KiB
16Accepted1/139ms1064 KiB
17Accepted1/132ms948 KiB
18Accepted1/112ms1552 KiB
19Wrong answer0/143ms1524 KiB
20Wrong answer0/132ms1572 KiB
21Wrong answer0/163ms1456 KiB
22Wrong answer0/127ms1456 KiB
23Accepted1/175ms1776 KiB
24Accepted1/179ms2732 KiB
25Accepted2/21ms320 KiB
26Accepted2/26ms568 KiB
27Wrong answer0/230ms968 KiB
28Wrong answer0/130ms948 KiB
29Accepted2/219ms1028 KiB
30Accepted1/163ms1528 KiB
31Accepted1/137ms2728 KiB
32Accepted2/22ms320 KiB
33Accepted2/264ms1348 KiB
34Accepted1/164ms1456 KiB
35Accepted2/267ms1456 KiB
36Accepted2/263ms1496 KiB
37Accepted2/263ms1456 KiB
38Accepted2/263ms1456 KiB
39Accepted1/12ms320 KiB