55412023-07-18 10:52:181478Ládapakolás raktárban (50)cpp17Accepted 50/5052ms12688 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, m, piles = 1, sum=0, a, b = 0;
    set<int> s;
    bool up = true;
    cin >> n >> m;
    for (int i=0; i<n; i++){
        cin >> a;
        if (sum + a > m || !up && a > b || s.count(a)){
            sum = a;
            s.clear();
            up = true;
            piles++;
        }
        else{
            sum += a;
            if (a < b) up = false;
        }
        s.insert(a);
        b = a;
    }
    cout << n - piles;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1960 KiB
2Accepted0/04ms2124 KiB
3Accepted2/22ms2124 KiB
4Accepted2/22ms2312 KiB
5Accepted2/22ms2360 KiB
6Accepted2/23ms2580 KiB
7Accepted2/22ms2692 KiB
8Accepted2/23ms2892 KiB
9Accepted3/33ms2884 KiB
10Accepted2/22ms2960 KiB
11Accepted2/23ms3252 KiB
12Accepted2/23ms3336 KiB
13Accepted3/34ms3576 KiB
14Accepted3/34ms3744 KiB
15Accepted3/36ms3864 KiB
16Accepted2/232ms4620 KiB
17Accepted3/341ms5216 KiB
18Accepted3/350ms6140 KiB
19Accepted3/337ms7112 KiB
20Accepted3/352ms10800 KiB
21Accepted3/346ms11436 KiB
22Accepted3/348ms12688 KiB