142642025-01-10 11:07:17TundeMaximális szorzat (50 pont)cpp17Time limit exceeded 5/50600ms780 KiB
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, k, b, db=0;
    long long szor=1;
    cin >> n >> k >> b;
    int t[n];
    for(int i=0; i<n; i++)
    {
        cin >> t[i];
        if(t[i]<0)
            ++db;
    }
    if(db<b)
        cout << -1;
    else
    {
        sort(t, t+n);
        int i=0;
        while(db!=b && i<k)
        {
            if(db%2==0)
            {
                if((t[db-1]+t[db-2])+(k-i)>=0)
                {
                    t[db-2]=0;
                    t[db-1]=0;
                    i-=t[db-2];
                    i-=t[db-1];
                    db-=2;
                }
            }
            else
            {
                if(t[db-1]+(k-i)>=0)
                {
                    i-=t[db-1];
                    t[db-1]=0;
                    db--;
                }
            }
        }
        if(db>b)
            cout << -1;
        else
        {
            while(i<k)
            {
                t[b]++;
                sort(t+b, t+n);
                i++;
            }
            for(int i=0; i<n; i++)
            {
                szor*=t[i];
                if(szor==0)
                    break;
            }
            cout << szor%(1000000000+7);
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base5/50
1Accepted0/01ms500 KiB
2Accepted0/01ms328 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms508 KiB
5Time limit exceeded0/0600ms316 KiB
6Accepted2/21ms316 KiB
7Wrong answer0/21ms500 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/221ms316 KiB
10Time limit exceeded0/2600ms372 KiB
11Time limit exceeded0/2600ms564 KiB
12Time limit exceeded0/1578ms564 KiB
13Wrong answer0/168ms316 KiB
14Time limit exceeded0/1598ms316 KiB
15Time limit exceeded0/1600ms564 KiB
16Time limit exceeded0/1600ms536 KiB
17Time limit exceeded0/1583ms564 KiB
18Accepted1/110ms580 KiB
19Wrong answer0/141ms564 KiB
20Wrong answer0/130ms564 KiB
21Wrong answer0/159ms564 KiB
22Wrong answer0/125ms548 KiB
23Time limit exceeded0/1577ms732 KiB
24Time limit exceeded0/1578ms568 KiB
25Wrong answer0/27ms316 KiB
26Wrong answer0/210ms316 KiB
27Wrong answer0/229ms424 KiB
28Wrong answer0/129ms404 KiB
29Accepted2/217ms564 KiB
30Wrong answer0/159ms780 KiB
31Time limit exceeded0/1600ms564 KiB
32Wrong answer0/23ms508 KiB
33Wrong answer0/261ms564 KiB
34Wrong answer0/164ms564 KiB
35Wrong answer0/2165ms564 KiB
36Wrong answer0/259ms564 KiB
37Wrong answer0/259ms564 KiB
38Wrong answer0/259ms564 KiB
39Wrong answer0/13ms332 KiB