253162026-02-19 09:28:49PappMatyasMaximális szorzat (50 pont)cpp17Wrong answer 6/5075ms2296 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, k, m;
vector<long long> v;
long long modder = 1000000007;

struct int2
{
    int x;
    int y;
};

static void Increase(int index)
{
    v[index]++;
    k--;
    if(index < n && k > 0)
    {
        if(v[index + 1] <= v[index])
        {
            Increase(index + 1);
        }
    }
}

static bool Compare(int2 a, int2 b)
{
    return a.x > b.x;
}

int main()
{
    cin >> n >> k >> m;
    v.resize(n);
    vector<int2> neg;

    int nCount = 0;

    for(int i = 0; i < n; i++)
    {
        cin >> v[i];

        if(v[i] < 0)
        {
            nCount++;
            int2 negative;
            negative.x = v[i];
            negative.y = i;
            neg.push_back(negative);
        }
    }
    if(nCount < m)
    {
        cout << -1;
        return 0;
    }

    sort(neg.begin(), neg.end(), Compare);

    int sz = neg.size();
    for(int i = 0; i < sz; i++)
    {
        if(nCount == m) break;
        int index = neg[i].y;
        v[index] = 0;
        k += neg[i].x;
        nCount--;
    }

    sort(v.begin(), v.end());

    int fnn = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] < 0) continue;
        fnn = i; break;
    }
    while(k > 0)
    {
        Increase(fnn);
    }
    nCount = 0;

    for(int i = 0; i < n; i++)
    {
        if(v[i] < 0)
        {
            nCount++;
        }
    }
    if(nCount != m)
    {
        cout << -1;
        return 0;
    }

    long long ans = 1;
    for(int i = 0; i < n; i++)
    {
        ans = (ans * abs(v[i])) % modder;
    }
    cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Wrong answer0/04ms316 KiB
6Accepted2/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/21ms316 KiB
10Wrong answer0/24ms316 KiB
11Wrong answer0/254ms1288 KiB
12Wrong answer0/157ms1188 KiB
13Wrong answer0/11ms316 KiB
14Wrong answer0/14ms564 KiB
15Wrong answer0/125ms1044 KiB
16Wrong answer0/128ms1200 KiB
17Wrong answer0/128ms1380 KiB
18Accepted1/110ms804 KiB
19Wrong answer0/157ms2240 KiB
20Wrong answer0/139ms2284 KiB
21Wrong answer0/175ms2184 KiB
22Accepted1/129ms2248 KiB
23Wrong answer0/167ms1588 KiB
24Wrong answer0/159ms1332 KiB
25Wrong answer0/22ms316 KiB
26Wrong answer0/27ms564 KiB
27Wrong answer0/237ms1200 KiB
28Wrong answer0/137ms1456 KiB
29Accepted2/218ms1428 KiB
30Wrong answer0/175ms2264 KiB
31Wrong answer0/143ms1188 KiB
32Runtime error0/22ms316 KiB
33Wrong answer0/275ms2264 KiB
34Wrong answer0/175ms2220 KiB
35Wrong answer0/275ms2296 KiB
36Wrong answer0/275ms2296 KiB
37Wrong answer0/275ms2164 KiB
38Wrong answer0/274ms2220 KiB
39Wrong answer0/11ms316 KiB