86052024-01-23 10:10:22GhostLeggyorsabb pénzkeresés (50)cpp17Wrong answer 10/50300ms6392 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

int main()
{
    int n, p, i, temp;
    cin >> n >> p;

    vector<pair<int,int>> pay(n);
    vector<int> pay2(n);
    for (i = 0; i < n; i++) {
        cin >> temp;
        pay[i].first = temp;
        pay[i].second = i;
        pay2[i] = temp;
    }

    sort(pay.begin(), pay.end());
    
    i = 0;
    int minday = INT_MAX;
    while (i < n) {
        int node = pay[i].second, value = pay[i].first, days = 1;
        bool canR = false, canL = false;

        if (value >= p) {
            cout << days;
            return 0;
        }
        if (node < n - 1) {
            canR = true;
        }
        if (node > 0) {
            canL = true;
        }
        int r = 1, l = 1;
        while (value < p && (canL || canR)) {
            int R = -1, L = -1;
            if (canR) {
                R = pay2[node + r];
            }
            if (canL) {
                L = pay2[node - l];
            }

            if (R >= L && canR) {
                value += R;
                r++;
                days++;
                if ((node + r) >= n) {
                    canR = false;
                }
            }
            else if (canL) {
                value += L;
                l++;
                days++;
                if ((node - l) <= 0) {
                    canL = false;
                }
            }
        }
        if (days < minday) {
            minday = days;
        }
        i++;
    }
    cout << minday;
}
SubtaskSumTestVerdictTimeMemory
base10/50
1Wrong answer0/03ms1688 KiB
2Time limit exceeded0/0300ms2304 KiB
3Accepted2/23ms2060 KiB
4Accepted2/23ms2272 KiB
5Accepted2/23ms2356 KiB
6Wrong answer0/217ms2740 KiB
7Wrong answer0/254ms2828 KiB
8Wrong answer0/275ms3228 KiB
9Accepted2/216ms3016 KiB
10Wrong answer0/264ms2780 KiB
11Accepted2/248ms5056 KiB
12Time limit exceeded0/2270ms3368 KiB
13Time limit exceeded0/2248ms3392 KiB
14Wrong answer0/2185ms5516 KiB
15Time limit exceeded0/2273ms3760 KiB
16Wrong answer0/2175ms5528 KiB
17Wrong answer0/2157ms5640 KiB
18Time limit exceeded0/2239ms4040 KiB
19Time limit exceeded0/2266ms4124 KiB
20Time limit exceeded0/2282ms4204 KiB
21Time limit exceeded0/2268ms6028 KiB
22Time limit exceeded0/2273ms4300 KiB
23Time limit exceeded0/2252ms4388 KiB
24Time limit exceeded0/2264ms4704 KiB
25Time limit exceeded0/2264ms4436 KiB
26Time limit exceeded0/2256ms6392 KiB
27Time limit exceeded0/2250ms6332 KiB