10182022-02-24 21:21:53Szin AttilaLádapakolás raktárban (50)cpp14Accepted 50/5029ms10676 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;

set<int> cur;
int n,m, sum;

bool tryAdd(int x) {
    return (cur.find(x) == cur.end() && sum + x <= m);
}


int main() {
   InTheNameOfGod;
    
    cin >> n >> m;
    vector<int> v(n);
    for(int &i : v) cin >> i;

    int cnt = 0;
    bool csucs = true;
    cur.insert(v[0]);
    sum = v[0];

    for(int i = 1; i < n; i++) {
        if(csucs && v[i] <= v[i-1]) csucs = false;
        if((!csucs && v[i] >= v[i-1]) || !tryAdd(v[i])) {
            cnt++;
            csucs = 1;
            sum = v[i];

            cur.clear();
            cur.insert(v[i]);
            continue;
        }

        sum += v[i];
        cur.insert(v[i]);
    }

    cout << n-cnt-1;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1768 KiB
2Accepted0/03ms2020 KiB
3Accepted2/21ms1932 KiB
4Accepted2/21ms1928 KiB
5Accepted2/21ms1912 KiB
6Accepted2/21ms1936 KiB
7Accepted2/22ms1948 KiB
8Accepted2/21ms1936 KiB
9Accepted3/31ms1944 KiB
10Accepted2/21ms1948 KiB
11Accepted2/21ms1960 KiB
12Accepted2/21ms1996 KiB
13Accepted3/32ms2052 KiB
14Accepted3/32ms2112 KiB
15Accepted3/33ms2184 KiB
16Accepted2/214ms3204 KiB
17Accepted3/314ms3872 KiB
18Accepted3/317ms4800 KiB
19Accepted3/316ms5404 KiB
20Accepted3/329ms9036 KiB
21Accepted3/321ms9460 KiB
22Accepted3/324ms10676 KiB