89412024-02-06 18:48:20hackemonLádapakolás raktárban (50)cpp17Accepted 50/5035ms12204 KiB
#include <bits/stdc++.h>
using namespace std;


int main() {
    //freopen("be2.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;


    vector<int> k(n); 
    int ans = 0; 

    for(int i = 0;i < n;i++ ) {
        cin >> k[i];
    }
    long long sum = 0; 

    set<int> f;
    f.insert(k[0]); 
    sum+= k[0];
    int counter = 1; 
   

    bool increasing = true;

    for(int i = 1;i < n;i++ ) { 
        if(f.find(k[i]) != f.end() || sum + k[i] > m) {
            f.clear();
            counter++;
            f.insert(k[i]);
            sum = k[i];
            increasing = true;
        } else if(k[i] < k[i-1]) {
            if(increasing) {
                increasing = false; 
            }
            f.insert(k[i]);
            sum+= k[i];
        } else {
            if(!increasing) {
                f.clear();
                counter++;
                increasing = true;
                sum = 0;
            }
            sum += k[i];
            f.insert(k[i]);
        }
    }

    cout << n - counter << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/04ms2192 KiB
3Accepted2/23ms2336 KiB
4Accepted2/23ms2492 KiB
5Accepted2/23ms2720 KiB
6Accepted2/23ms2936 KiB
7Accepted2/23ms2900 KiB
8Accepted2/23ms2908 KiB
9Accepted3/33ms3036 KiB
10Accepted2/23ms3124 KiB
11Accepted2/23ms3132 KiB
12Accepted2/23ms3148 KiB
13Accepted3/34ms3496 KiB
14Accepted3/34ms3516 KiB
15Accepted3/34ms3552 KiB
16Accepted2/217ms4548 KiB
17Accepted3/320ms5220 KiB
18Accepted3/324ms6452 KiB
19Accepted3/320ms6924 KiB
20Accepted3/335ms10664 KiB
21Accepted3/328ms11192 KiB
22Accepted3/328ms12204 KiB