253212026-02-19 09:57:38PappMatyasMaximális szorzat (50 pont)cpp17Elfogadva 50/5076ms2348 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 - 1 && 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva0/01ms316 KiB
4Elfogadva0/01ms316 KiB
5Elfogadva0/04ms316 KiB
6Elfogadva2/21ms368 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms500 KiB
10Elfogadva2/26ms472 KiB
11Elfogadva2/256ms1076 KiB
12Elfogadva1/159ms1192 KiB
13Elfogadva1/11ms316 KiB
14Elfogadva1/16ms580 KiB
15Elfogadva1/120ms1116 KiB
16Elfogadva1/128ms1328 KiB
17Elfogadva1/123ms1432 KiB
18Elfogadva1/112ms808 KiB
19Elfogadva1/157ms2248 KiB
20Elfogadva1/143ms2308 KiB
21Elfogadva1/176ms2116 KiB
22Elfogadva1/130ms2348 KiB
23Elfogadva1/170ms1712 KiB
24Elfogadva1/161ms1308 KiB
25Elfogadva2/21ms316 KiB
26Elfogadva2/27ms796 KiB
27Elfogadva2/237ms1200 KiB
28Elfogadva1/137ms1376 KiB
29Elfogadva2/219ms1200 KiB
30Elfogadva1/176ms2220 KiB
31Elfogadva1/132ms1076 KiB
32Elfogadva2/22ms508 KiB
33Elfogadva2/276ms2328 KiB
34Elfogadva1/175ms2272 KiB
35Elfogadva2/276ms2288 KiB
36Elfogadva2/276ms2304 KiB
37Elfogadva2/276ms2220 KiB
38Elfogadva2/275ms2220 KiB
39Elfogadva1/11ms316 KiB