8722022-01-21 22:01:09Valaki2Ládapakolás raktárban (50)cpp14Wrong answer 6/5028ms11308 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int n, k;
vector<int> v;

set<int> s;
int max_pos;
int sum;
int cnt;

void new_segment(int i) {
    s.clear();
    sum = v[i];
    max_pos = i;
    s.insert(v[i]);
    cnt++;
}

void same_segment(int i) {
    s.insert(v[i]);
    if(v[i] > v[max_pos]) {
        max_pos = i;
    }
}

void solve() {
    cin >> n >> k;
    v.assign(1 + n, 0);
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    for(int i = 1; i <= n; i++) {
        sum += v[i];
        if(s.count(i)) {
            new_segment(i);
            continue;
        }
        if(sum > k) {
            new_segment(i);
            continue;
        }
        if(v[i] > v[max_pos] && max_pos == i - 1) {
            same_segment(i);
            continue;
        }
        if(v[i] < v[i - 1]) {
            same_segment(i);
            continue;
        }
    }
    cout << n - cnt - 1 << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

/*
12 16
1 3 5 4 2 6 8 7 6 5 3 4
*/
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/02ms1856 KiB
2Wrong answer0/03ms2076 KiB
3Wrong answer0/21ms1964 KiB
4Wrong answer0/21ms1972 KiB
5Accepted2/21ms1976 KiB
6Accepted2/21ms1984 KiB
7Accepted2/21ms1980 KiB
8Wrong answer0/21ms1988 KiB
9Wrong answer0/31ms1988 KiB
10Wrong answer0/21ms1996 KiB
11Wrong answer0/21ms2004 KiB
12Wrong answer0/22ms2028 KiB
13Wrong answer0/32ms2068 KiB
14Wrong answer0/33ms2252 KiB
15Wrong answer0/33ms2296 KiB
16Wrong answer0/214ms3880 KiB
17Wrong answer0/316ms4556 KiB
18Wrong answer0/318ms5480 KiB
19Wrong answer0/317ms6056 KiB
20Wrong answer0/317ms8112 KiB
21Wrong answer0/324ms9528 KiB
22Wrong answer0/328ms11308 KiB