155372025-02-20 11:23:42MatematikaMaximális szorzat (50 pont)cpp17Wrong answer 7/5082ms2344 KiB
#include <bits/stdc++.h>

using namespace std;
#define int long long

signed main()
{
    int n,k,m,kezdes=-1,negativ=0,ossz=1; cin >> n >> k >> m;
    priority_queue<int, vector<int>, greater<int>> pq;
    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";
    if(negativ==m && negativ==n)
    {
        for(auto& z:vec)
            if(z<-1)
                pq.push(z);
        while(k>0)
        {
            if(pq.empty())
            {
                cout << "-1";
                return 0;
            }
            int x=pq.top();
            //cerr << x << "\n";
            pq.pop();
            x++;
            if(x!=-1)
                pq.push(x);
            k--;
        }
        while(!pq.empty())
        {
            ossz*=pq.top();
            pq.pop();
        }
        for(auto& z:vec)
            if(z>=0)
                ossz*=z;
        cout << ossz;
        return 0;
    }
    else
    {
        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;
        }
        for(auto& z:vec)
            if(z>=0)
                pq.push(z);
        while(k>0 && !pq.empty())
        {
            int x=pq.top();
            //cerr << x << "\n";
            pq.pop();
            x++;
            pq.push(x);
            k--;
        }
        while(!pq.empty())
        {
            ossz*=pq.top();
            pq.pop();
        }
        for(auto& z:vec)
            if(z<0)
                ossz*=z;
        cout << ossz;
        return 0;
    }
}
/*4 2 4
-3 -1 -1 -1
*/
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms500 KiB
5Wrong answer0/04ms476 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms396 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/27ms564 KiB
11Wrong answer0/272ms2344 KiB
12Wrong answer0/178ms2340 KiB
13Wrong answer0/11ms412 KiB
14Wrong answer0/17ms564 KiB
15Accepted1/120ms564 KiB
16Wrong answer0/141ms1076 KiB
17Accepted1/120ms564 KiB
18Accepted1/113ms1652 KiB
19Wrong answer0/170ms2340 KiB
20Wrong answer0/156ms2220 KiB
21Wrong answer0/182ms2336 KiB
22Accepted1/127ms1712 KiB
23Wrong answer0/175ms1836 KiB
24Wrong answer0/178ms2332 KiB
25Wrong answer0/21ms316 KiB
26Wrong answer0/26ms476 KiB
27Wrong answer0/246ms1436 KiB
28Wrong answer0/146ms1440 KiB
29Accepted2/218ms564 KiB
30Wrong answer0/161ms1076 KiB
31Accepted1/141ms1080 KiB
32Wrong answer0/22ms316 KiB
33Wrong answer0/261ms1076 KiB
34Wrong answer0/161ms1076 KiB
35Wrong answer0/264ms1076 KiB
36Wrong answer0/261ms1076 KiB
37Wrong answer0/259ms1076 KiB
38Wrong answer0/261ms1076 KiB
39Wrong answer0/12ms316 KiB