44472023-03-28 10:34:49ZsofiaKeresztelyLádapakolás raktárban (50)cpp14Accepted 50/5032ms7712 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    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/03ms1824 KiB
2Accepted0/04ms2060 KiB
3Accepted2/23ms2260 KiB
4Accepted2/23ms2448 KiB
5Accepted2/23ms2668 KiB
6Accepted2/22ms2748 KiB
7Accepted2/23ms2976 KiB
8Accepted2/23ms3092 KiB
9Accepted3/32ms3176 KiB
10Accepted2/23ms3456 KiB
11Accepted2/23ms3484 KiB
12Accepted2/23ms3388 KiB
13Accepted3/33ms3512 KiB
14Accepted3/34ms3604 KiB
15Accepted3/34ms3600 KiB
16Accepted2/216ms3596 KiB
17Accepted3/317ms3604 KiB
18Accepted3/319ms3600 KiB
19Accepted3/318ms3872 KiB
20Accepted3/332ms7208 KiB
21Accepted3/327ms7128 KiB
22Accepted3/327ms7712 KiB