146852025-01-27 19:49:09feheristvanLeggyorsabb pénzkeresés (50)cpp17Wrong answer 0/50300ms6980 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int minNap(int n, int p, int db, int ossz, const vector<int>& v) {
    // Base case: If the target is reached, return the current day count
    if (ossz >= p) {
        return db;
    }
    // Base case: If no more elements are left, return an impossible value
    if (n < 0) {
        return INT_MAX;
    }
    // Recursive step: Explore both including and excluding the current day
    int include = minNap(n - 1, p, db + 1, ossz + v[n], v); // Include the current day's work
    int exclude = minNap(n - 1, p, db, ossz, v);           // Skip the current day

    // Return the minimum of the two results
    return min(include, exclude);
}

int main() {
    int n, p;
    cin >> n >> p;
    vector<int> v(n);
    for (auto& i : v)
        cin >> i;

    int result = minNap(n - 1, p, 0, 0, v); // Start from the last day
    if (result == INT_MAX) {
        cout << -1 << endl; // Output -1 if no valid solution exists
    } else {
        cout << result << endl; // Output the minimal number of days
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms316 KiB
2Time limit exceeded0/0291ms6964 KiB
3Time limit exceeded0/2289ms316 KiB
4Time limit exceeded0/2289ms316 KiB
5Time limit exceeded0/2300ms316 KiB
6Time limit exceeded0/2280ms956 KiB
7Time limit exceeded0/2280ms820 KiB
8Time limit exceeded0/2280ms1012 KiB
9Time limit exceeded0/2300ms820 KiB
10Time limit exceeded0/2277ms820 KiB
11Time limit exceeded0/2277ms6964 KiB
12Time limit exceeded0/2277ms6960 KiB
13Time limit exceeded0/2300ms6944 KiB
14Time limit exceeded0/2289ms6964 KiB
15Time limit exceeded0/2291ms6944 KiB
16Time limit exceeded0/2289ms6964 KiB
17Time limit exceeded0/2300ms6964 KiB
18Time limit exceeded0/2284ms6944 KiB
19Time limit exceeded0/2284ms6964 KiB
20Time limit exceeded0/2286ms6960 KiB
21Time limit exceeded0/2300ms6972 KiB
22Time limit exceeded0/2287ms6968 KiB
23Time limit exceeded0/2287ms6964 KiB
24Time limit exceeded0/2287ms6968 KiB
25Time limit exceeded0/2300ms6948 KiB
26Time limit exceeded0/2282ms6944 KiB
27Time limit exceeded0/2282ms6980 KiB