147412025-01-31 10:41:15markfsibianMaximális szorzat (50 pont)cpp17Wrong answer 3/50600ms760 KiB
#include <iostream>
#include <climits>

using namespace std;

int neg, n, up, v[100001];

int main()
{
    cin >> n >> up >> neg;
    int mini = INT_MAX, t, ind, negs = 0, z = 0;
    for (int i = 1; i <= n; ++i)
    {

        cin >> t;
        if (t < 0)
            negs++;
        if (t == 0)
            z++;
        v[i] = t;
    }
    
    
    int negmaxi, negind, f = 0;
    while (negs > neg)
    {
        negmaxi = INT_MIN;
        for (int i = 1; i <= n; ++i)
        {
            if (v[i] > negmaxi && v[i] < 0)
            {
                negind = i;
                negmaxi = v[i];
            }
        }
        v[negind] = v[negind] + up;
        up = 0;
        if (v[negind] - 1 > 0)
        {
            up = v[negind] - 1;
            v[negind] = 1;
        }
        if (v[negind] < 0)
        {
            f = 1;
            break;
        }
        negs--;
        
    }

    if (f)
        cout << -1;
    else
    {

        

        while (z > 0)
        {
            for (int i = 1; i <= n; ++i)
                if (v[i] == 0 && up > 0)
                {
                    v[i] = 1;
                    up--;
                    z--;
                }
            
        }
        

        while (up)
        {
            for (int i = 1; i <= n; ++i)
            {

                if (v[i] < mini && v[i] > 0)
                {
                    mini = v[i];
                    ind = i;
                }
            }
            v[ind]++;
            up--;
            mini++;
            
        }
        
        

        int s = 1;
        for (int i = 1; i <= n; ++i)
            s = s * v[i];
        cout << endl << s << endl;
    }

}

SubtaskSumTestVerdictTimeMemory
base3/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms508 KiB
5Wrong answer0/0136ms444 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/24ms316 KiB
10Wrong answer0/2335ms452 KiB
11Time limit exceeded0/2600ms576 KiB
12Time limit exceeded0/1577ms536 KiB
13Wrong answer0/112ms316 KiB
14Time limit exceeded0/1582ms316 KiB
15Accepted1/1338ms756 KiB
16Time limit exceeded0/1584ms564 KiB
17Accepted1/1144ms564 KiB
18Time limit exceeded0/1580ms756 KiB
19Time limit exceeded0/1580ms564 KiB
20Time limit exceeded0/1600ms564 KiB
21Time limit exceeded0/1584ms756 KiB
22Time limit exceeded0/1588ms760 KiB
23Time limit exceeded0/1574ms552 KiB
24Time limit exceeded0/1600ms564 KiB
25Wrong answer0/27ms316 KiB
26Wrong answer0/2254ms316 KiB
27Time limit exceeded0/2578ms756 KiB
28Time limit exceeded0/1583ms564 KiB
29Time limit exceeded0/2578ms564 KiB
30Time limit exceeded0/1583ms564 KiB
31Accepted1/132ms568 KiB
32Wrong answer0/2483ms316 KiB
33Time limit exceeded0/2600ms564 KiB
34Time limit exceeded0/1600ms708 KiB
35Time limit exceeded0/2583ms564 KiB
36Time limit exceeded0/2579ms748 KiB
37Time limit exceeded0/2580ms564 KiB
38Time limit exceeded0/2600ms564 KiB
39Wrong answer0/148ms316 KiB