146842025-01-27 19:46:33feheristvanLeggyorsabb pénzkeresés (50)cpp17Wrong answer 0/50300ms6968 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) {
    if (ossz >= p) {
        return db; // Base case: reached the target amount
    }
    if (n < 0) {
        return INT_MAX; // Base case: no more elements to add
    }
    // Recursively compute the minimal day by considering two choices:
    // 1. Include v[n] in the total and increment the day count
    // 2. Skip the current day
    int include = minNap(n - 1, p, db + 1, ossz + v[n], v);
    int exclude = minNap(n - 1, p, db, ossz, v);

    return min(include, exclude); // Return the minimum of both choices
}

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 element
    if (result == INT_MAX) {
        cout << -1 << endl; // Output -1 if it's impossible to reach the target
    } else {
        cout << result << endl; // Output the minimum number of days
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms316 KiB
2Time limit exceeded0/0277ms6964 KiB
3Time limit exceeded0/2275ms316 KiB
4Time limit exceeded0/2277ms500 KiB
5Time limit exceeded0/2300ms316 KiB
6Time limit exceeded0/2282ms820 KiB
7Time limit exceeded0/2284ms1012 KiB
8Time limit exceeded0/2284ms820 KiB
9Time limit exceeded0/2300ms820 KiB
10Time limit exceeded0/2280ms820 KiB
11Time limit exceeded0/2282ms6948 KiB
12Time limit exceeded0/2282ms6960 KiB
13Time limit exceeded0/2300ms6964 KiB
14Time limit exceeded0/2279ms6964 KiB
15Time limit exceeded0/2280ms6964 KiB
16Time limit exceeded0/2280ms6964 KiB
17Time limit exceeded0/2300ms6948 KiB
18Time limit exceeded0/2280ms6968 KiB
19Time limit exceeded0/2280ms6964 KiB
20Time limit exceeded0/2280ms6956 KiB
21Time limit exceeded0/2300ms6952 KiB
22Time limit exceeded0/2286ms6964 KiB
23Time limit exceeded0/2287ms6952 KiB
24Time limit exceeded0/2287ms6960 KiB
25Time limit exceeded0/2300ms6952 KiB
26Time limit exceeded0/2286ms6960 KiB
27Time limit exceeded0/2286ms6964 KiB