114772024-10-05 21:29:04madvirMaximális szorzat (50 pont)cpp14Wrong answer 4/50598ms1272 KiB
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n, k, b;
    cin >> n >> k >> b;
    long long a[n], neg=0, negcard=0, ub=b, n0=0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        if(a[i]<0) {
            ub--;
            if(ub<=0) {
                neg=neg-a[i];
                negcard++;
                a[i]=1;
            }
        }
        else {
            if(a[i]==0) {
                n0++;
                a[i]=1;
            }
        }
    }
    if(k>=neg) {
        k=k-neg-negcard;
        if(n0>k) {
            cout << 0;
        }
        else {
            int mini=1;
            k-=n0;
            while(k>0) {
                for(int i=0; i<n && k>0; i++) {
                    if(a[i]==mini) {
                        a[i]++;
                        k--;
                    }
                }
                mini++;
            }
            long long p=1;
            for(int i=0; i<n; i++) {
                p=p*a[i];
            }
            cout << p;
        }
    }
    else {
        cout << -1;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms360 KiB
2Accepted0/03ms504 KiB
3Wrong answer0/03ms296 KiB
4Wrong answer0/03ms360 KiB
5Wrong answer0/04ms376 KiB
6Wrong answer0/22ms360 KiB
7Wrong answer0/22ms360 KiB
8Wrong answer0/23ms504 KiB
9Wrong answer0/23ms360 KiB
10Wrong answer0/243ms492 KiB
11Time limit exceeded0/2589ms1100 KiB
12Time limit exceeded0/1595ms1060 KiB
13Wrong answer0/13ms504 KiB
14Wrong answer0/16ms380 KiB
15Accepted1/117ms744 KiB
16Wrong answer0/119ms800 KiB
17Accepted1/117ms760 KiB
18Accepted1/110ms744 KiB
19Time limit exceeded0/1597ms1128 KiB
20Time limit exceeded0/1597ms1144 KiB
21Wrong answer0/152ms1128 KiB
22Time limit exceeded0/1598ms1000 KiB
23Wrong answer0/152ms1272 KiB
24Wrong answer0/148ms1128 KiB
25Wrong answer0/22ms360 KiB
26Wrong answer0/26ms488 KiB
27Wrong answer0/228ms744 KiB
28Wrong answer0/128ms888 KiB
29Wrong answer0/2118ms784 KiB
30Wrong answer0/152ms1128 KiB
31Accepted1/135ms1272 KiB
32Wrong answer0/2194ms268 KiB
33Wrong answer0/252ms1128 KiB
34Wrong answer0/154ms1148 KiB
35Wrong answer0/252ms1128 KiB
36Wrong answer0/252ms1128 KiB
37Wrong answer0/252ms1128 KiB
38Wrong answer0/252ms1052 KiB
39Wrong answer0/121ms632 KiB