253202026-02-19 09:55:23PappMatyasMaximális szorzat (50 pont)cpp17Wrong answer 36/5076ms2324 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, k, m;
vector<long long> v;
long long modder = 1000000000 + 7;

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--;
    }

    if(k < 0)
    {
        cout << -1;
        return 0;
    }

    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
base36/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms332 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/26ms316 KiB
11Accepted2/256ms1076 KiB
12Accepted1/159ms1196 KiB
13Accepted1/11ms316 KiB
14Accepted1/16ms564 KiB
15Accepted1/119ms1092 KiB
16Accepted1/128ms1192 KiB
17Accepted1/123ms1200 KiB
18Accepted1/112ms564 KiB
19Accepted1/157ms2184 KiB
20Accepted1/141ms2124 KiB
21Accepted1/176ms2188 KiB
22Accepted1/130ms2220 KiB
23Accepted1/170ms1712 KiB
24Accepted1/159ms1248 KiB
25Wrong answer0/21ms316 KiB
26Accepted2/27ms564 KiB
27Accepted2/237ms1240 KiB
28Accepted1/137ms1200 KiB
29Accepted2/219ms1428 KiB
30Wrong answer0/176ms2244 KiB
31Accepted1/132ms1076 KiB
32Runtime error0/22ms316 KiB
33Wrong answer0/276ms2220 KiB
34Accepted1/175ms2256 KiB
35Accepted2/276ms2220 KiB
36Wrong answer0/276ms2220 KiB
37Wrong answer0/275ms2324 KiB
38Wrong answer0/276ms2324 KiB
39Wrong answer0/12ms316 KiB