201232026-01-02 11:49:57szabelrMaximális szorzat (50 pont)cpp17Wrong answer 38/5028ms1084 KiB
// Maximális szorzat.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k, b;
    cin >> n >> k >> b;
    vector<int> sor (n);
    for (int i = 0; i < n; i++)
        cin >> sor[i];
    sort(sor.begin(), sor.end());
    int firstnegative=-1;
    for (int i=n-1; i>=0; i--)
    {
        if (sor[i] < 0)
        {
            firstnegative = i;
            break;
        }
            
    }
    if (firstnegative < b-1)
    {
        cout << -1;
        return 0;
    }
    for (int i = b; i<=firstnegative; i++)
    {
        k = k - (0 - sor[i]);
        sor[i] = 0;    
    }
    int i;
        i = b;
    
    int elotte = 1;
    while (k > 0 and i<n-1)
    {
        long long need = (sor[i + 1] - sor[i]) * elotte;
        if (k >= need)
        {
            k -= need;
            elotte++;
            i++;
        }
        else {
            int add = k / elotte;
            int extra = k % elotte;
            int base_val = sor[i];
            for (int j = 0; j < elotte; j++)
            {
                sor[b+j] = base_val + add + (j < extra ? 1 : 0);
            }
            k = 0;
        }
    }
    if (k > 0)
    {
        int count = n - b;
        int add = k / count;
        int extra = k % count;
        int base_val = sor[n - 1]; 
        for (int j = 0; j < count; j++)
        {
            sor[b+j] = base_val + add + (j < extra ? 1 : 0);
        }
    }
    long long product = 1;
    for (int i = 0; i < n; i++)
        product = (product * (abs(sor[i]) % 1000000007))% 1000000007;
    cout << product;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base38/50
1Accepted0/01ms500 KiB
2Accepted0/01ms316 KiB
3Accepted0/01ms316 KiB
4Accepted0/01ms316 KiB
5Accepted0/04ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Wrong answer0/21ms316 KiB
10Accepted2/23ms464 KiB
11Accepted2/226ms820 KiB
12Accepted1/127ms820 KiB
13Accepted1/11ms316 KiB
14Accepted1/13ms316 KiB
15Wrong answer0/112ms564 KiB
16Accepted1/112ms564 KiB
17Wrong answer0/110ms564 KiB
18Accepted1/14ms564 KiB
19Runtime error0/121ms828 KiB
20Runtime error0/116ms1084 KiB
21Runtime error0/127ms824 KiB
22Runtime error0/112ms836 KiB
23Accepted1/128ms820 KiB
24Accepted1/127ms820 KiB
25Accepted2/21ms316 KiB
26Accepted2/23ms316 KiB
27Runtime error0/214ms628 KiB
28Runtime error0/114ms568 KiB
29Accepted2/212ms568 KiB
30Accepted1/128ms820 KiB
31Wrong answer0/123ms636 KiB
32Accepted2/21ms508 KiB
33Accepted2/228ms1012 KiB
34Accepted1/128ms820 KiB
35Accepted2/228ms820 KiB
36Accepted2/228ms820 KiB
37Accepted2/228ms820 KiB
38Accepted2/228ms1012 KiB
39Accepted1/11ms316 KiB