116562024-11-03 17:26:40MagyarKendeSZLGMaximális szorzat (50 pont)cpp17Runtime error 43/5075ms1556 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;
    priority_queue<ll, vector<ll>, greater<ll>> pq;

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

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

    sort(neg.begin(), neg.end());
    ll result = 1;

    for (int i = 0; i < B; i++) {
        result *= -neg[i];
        result %= MOD;
    }

    for (int i = B; i < neg.size(); i++) {
        K += neg[i];
        pq.push(0);
    }

    if (K < 0) {
        cout << "-1\n";
        exit(0);
    }

    while (K--) {
        ll mn = pq.top();
        pq.pop();
        pq.push((mn + 1) % MOD);
    }

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

    cout << result << "\n";
}
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms320 KiB
2Accepted0/01ms320 KiB
3Accepted0/01ms320 KiB
4Accepted0/01ms320 KiB
5Accepted0/04ms568 KiB
6Accepted2/21ms320 KiB
7Accepted2/21ms320 KiB
8Accepted2/21ms320 KiB
9Accepted2/21ms320 KiB
10Accepted2/27ms572 KiB
11Accepted2/271ms1452 KiB
12Accepted1/175ms1544 KiB
13Accepted1/11ms320 KiB
14Accepted1/17ms480 KiB
15Accepted1/119ms896 KiB
16Accepted1/137ms948 KiB
17Accepted1/120ms948 KiB
18Accepted1/112ms948 KiB
19Runtime error0/143ms1532 KiB
20Runtime error0/132ms1552 KiB
21Runtime error0/161ms1552 KiB
22Runtime error0/125ms1556 KiB
23Accepted1/175ms1100 KiB
24Accepted1/175ms1456 KiB
25Accepted2/22ms320 KiB
26Accepted2/26ms568 KiB
27Runtime error0/229ms948 KiB
28Runtime error0/129ms992 KiB
29Accepted2/218ms948 KiB
30Accepted1/161ms1460 KiB
31Accepted1/135ms1452 KiB
32Accepted2/23ms320 KiB
33Accepted2/261ms1520 KiB
34Accepted1/163ms1556 KiB
35Accepted2/264ms1452 KiB
36Accepted2/261ms1460 KiB
37Accepted2/261ms1404 KiB
38Accepted2/261ms1556 KiB
39Accepted1/12ms320 KiB