201252026-01-02 11:51:56szabelrMaximális szorzat (50 pont)cpp17Hibás válasz 41/5027ms1268 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);
    long long n, k, b;
    cin >> n >> k >> b;
    vector<long long> sor (n);
    for (int i = 0; i < n; i++)
        cin >> sor[i];
    sort(sor.begin(), sor.end());
    long long 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;
        if (k < 0)
        {
            cout << -1;
            return 0;
    }
    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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base41/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms500 KiB
3Elfogadva0/01ms316 KiB
4Elfogadva0/01ms316 KiB
5Elfogadva0/03ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms388 KiB
9Hibás válasz0/21ms508 KiB
10Elfogadva2/23ms508 KiB
11Elfogadva2/224ms1128 KiB
12Elfogadva1/125ms1076 KiB
13Elfogadva1/11ms316 KiB
14Elfogadva1/13ms420 KiB
15Elfogadva1/110ms820 KiB
16Elfogadva1/112ms1004 KiB
17Elfogadva1/19ms820 KiB
18Elfogadva1/14ms820 KiB
19Futási hiba0/119ms1224 KiB
20Futási hiba0/114ms1076 KiB
21Futási hiba0/125ms1216 KiB
22Futási hiba0/110ms1220 KiB
23Elfogadva1/127ms1084 KiB
24Elfogadva1/125ms1076 KiB
25Elfogadva2/21ms316 KiB
26Elfogadva2/23ms316 KiB
27Futási hiba0/212ms828 KiB
28Futási hiba0/113ms828 KiB
29Elfogadva2/210ms820 KiB
30Elfogadva1/125ms1076 KiB
31Elfogadva1/120ms1036 KiB
32Elfogadva2/21ms316 KiB
33Elfogadva2/225ms1076 KiB
34Elfogadva1/125ms1076 KiB
35Elfogadva2/225ms1268 KiB
36Elfogadva2/225ms1076 KiB
37Elfogadva2/225ms1076 KiB
38Elfogadva2/225ms1092 KiB
39Elfogadva1/12ms508 KiB