155182025-02-20 10:33:48MatematikaMaximális szorzat (50 pont)cpp17Wrong answer 6/5079ms2344 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main()
{
    int n,k,m,kezdes=-1,negativ=0; cin >> n >> k >> m;
    vector<int> vec(n);
    for(auto& z:vec)
    {
        cin >> z;
        if(z<0)
            negativ++;
    }
    //cerr << negativ << "\n";
    if(m>negativ)
    {
        cout << "-1";
        return 0;
    }
    sort(vec.begin(),vec.end());
    for(int i=0; i<n && vec[i]<0; i++)
        kezdes=i;
    //cerr << kezdes << "\n";
    for(int i=0; i<negativ-m; i++)
    {
        k+=vec[kezdes-i];
        vec[kezdes-i]=0;
    }
    /*for(auto z:vec)
        cerr << z << " ";*/
    if(k<0)
    {
        cout << "-1";
        return 0;
    }
    priority_queue<int, vector<int>, greater<int>> pq;
    for(auto& z:vec)
        if(z>=0)
            pq.push(z);
    while(k>0)
    {
        int x=pq.top();
        //cerr << x << "\n";
        pq.pop();
        x++;
        pq.push(x);
        k--;
    }
    int ossz=1;
    while(!pq.empty())
    {
        ossz*=pq.top();
        pq.pop();
    }
    for(auto& z:vec)
        if(z<0)
            ossz*=z;
    cout << ossz;
    return 0;
}
/*5 3 0
-1 1 1 1 1
*/
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/04ms472 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms508 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/27ms604 KiB
11Wrong answer0/272ms2336 KiB
12Wrong answer0/179ms2344 KiB
13Wrong answer0/11ms316 KiB
14Wrong answer0/18ms580 KiB
15Accepted1/120ms564 KiB
16Wrong answer0/141ms1072 KiB
17Accepted1/120ms564 KiB
18Accepted1/112ms1200 KiB
19Runtime error0/141ms1200 KiB
20Runtime error0/130ms1192 KiB
21Runtime error0/159ms1192 KiB
22Runtime error0/124ms1192 KiB
23Wrong answer0/175ms1824 KiB
24Wrong answer0/179ms2212 KiB
25Wrong answer0/22ms316 KiB
26Wrong answer0/26ms316 KiB
27Runtime error0/228ms800 KiB
28Runtime error0/128ms800 KiB
29Accepted2/217ms564 KiB
30Wrong answer0/159ms1268 KiB
31Accepted1/141ms1076 KiB
32Wrong answer0/22ms512 KiB
33Wrong answer0/259ms1076 KiB
34Wrong answer0/161ms1076 KiB
35Wrong answer0/263ms1268 KiB
36Wrong answer0/259ms1100 KiB
37Wrong answer0/259ms1260 KiB
38Wrong answer0/259ms1192 KiB
39Wrong answer0/12ms316 KiB