146882025-01-27 19:57:19feheristvanLeggyorsabb pénzkeresés (50)cpp17Wrong answer 4/5030ms820 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 ossz = v[0], db = 0, mindb = INT_MAX, elso = 0;
    for(int i = 1; i < n; i ++){
        if(ossz < p){
            ossz += v[i];
            db ++;
        }
        if(ossz >= p){
            if(mindb > db){
                mindb = db;
            }
            ossz -= v[elso];
            elso += 1;
            db --;
        }
    }
    cout << mindb;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/028ms756 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/24ms316 KiB
7Wrong answer0/24ms316 KiB
8Wrong answer0/24ms316 KiB
9Wrong answer0/24ms508 KiB
10Wrong answer0/24ms316 KiB
11Wrong answer0/228ms564 KiB
12Wrong answer0/228ms800 KiB
13Wrong answer0/230ms564 KiB
14Wrong answer0/228ms800 KiB
15Wrong answer0/228ms820 KiB
16Wrong answer0/228ms668 KiB
17Wrong answer0/228ms564 KiB
18Wrong answer0/228ms568 KiB
19Wrong answer0/228ms564 KiB
20Wrong answer0/228ms564 KiB
21Wrong answer0/228ms784 KiB
22Wrong answer0/228ms564 KiB
23Wrong answer0/228ms756 KiB
24Wrong answer0/228ms564 KiB
25Wrong answer0/229ms564 KiB
26Wrong answer0/228ms564 KiB
27Wrong answer0/228ms564 KiB