166472025-05-07 18:08:06sztomiMaximális szorzat (50 pont)cpp17Wrong answer 43/5028ms1096 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k, b;
    cin >> n >> k >> b;
    vector<int> poz;
    vector<int> neg;
    int temp;
    for(int i = 0; i < n; i++){
        cin >> temp;
        if(temp >= 0){
            poz.push_back(temp);
        }
        else if(temp < 0){
            neg.push_back(temp);
        }
    }
    sort(neg.begin(), neg.end(), greater<int>());


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

    int kell = neg.size()-b;
    int elhasznal = 0;
    for(int i = 0; i < kell; i++){
        elhasznal += -neg[i];
        poz.push_back(0);
    }

    if(elhasznal > k){
        cout << "-1\n";
        return 0;
    }
    k -= elhasznal;

    long long ret = 1;
    long long mod = 1e9 + 7;
    if(poz.size() > 0){
        sort(poz.begin(), poz.end());
        int elozo = 0;
        int meddig = 0;
        int feltolt = 0;
        for(int i = 1; i < poz.size(); i++){
            elozo = elozo + (poz[i]-poz[i-1])*i;
            if(elozo <= k){
                meddig = i;
                feltolt = elozo;
            }
            else{
                break;
            }
        }

        k -= feltolt;
        int also_db = meddig+1;
        int also = poz[meddig];

        //cout << "also: " << also << " also_db: " <<also_db << " " << k << "\n";

        //cout << "also_db " << also_db << " k " << k << "\n";
        int osszes_novel = k / also_db;
        also += osszes_novel;
        k -= osszes_novel*also_db;
        //cout << "osszes_novel " << osszes_novel << "\n";

        also_db -= k;
        //cout << "vegso alsodb " << also_db << " " << also << "\n";
        for(int i = 0; i < also_db; i++){
            ret *= also;
            ret %= mod;
        }
        for(int i = 0; i < k; i++){
            ret *= (also + 1);
            ret %= mod;
        }

        for(int i = also_db+k; i < poz.size(); i++){
            ret *= poz[i];
            ret %= mod;
        }
    }

    for(int i = neg.size()-b; i < neg.size(); i++){
        ret *= abs(neg[i]);
        ret %= mod;
        //cout << "raszoroz " << neg[i] << "\n";
    }
    cout << ret << "\n";
}
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/01ms316 KiB
2Accepted0/01ms508 KiB
3Accepted0/01ms500 KiB
4Accepted0/01ms316 KiB
5Accepted0/03ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/23ms316 KiB
11Accepted2/226ms1000 KiB
12Accepted1/127ms1012 KiB
13Accepted1/11ms316 KiB
14Accepted1/13ms508 KiB
15Accepted1/18ms648 KiB
16Accepted1/112ms820 KiB
17Accepted1/110ms740 KiB
18Accepted1/16ms820 KiB
19Wrong answer0/123ms1028 KiB
20Wrong answer0/117ms1012 KiB
21Wrong answer0/128ms1064 KiB
22Wrong answer0/113ms1016 KiB
23Accepted1/128ms916 KiB
24Accepted1/127ms1096 KiB
25Accepted2/21ms316 KiB
26Accepted2/23ms316 KiB
27Wrong answer0/214ms732 KiB
28Wrong answer0/114ms820 KiB
29Accepted2/212ms644 KiB
30Accepted1/128ms1044 KiB
31Accepted1/112ms1060 KiB
32Accepted2/21ms316 KiB
33Accepted2/228ms932 KiB
34Accepted1/127ms948 KiB
35Accepted2/228ms952 KiB
36Accepted2/228ms1024 KiB
37Accepted2/228ms948 KiB
38Accepted2/228ms948 KiB
39Accepted1/11ms316 KiB