105922024-04-06 11:04:40MagyarKendeSZLGLádapakolás raktárban (50)cpp17Accepted 50/5056ms12860 KiB
#include <bits/stdc++.h>

#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define size(v) (int)v.size()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);

    int N, M;
    cin >> N >> M;

    vector<int> boxS(N);
    cinv(boxS);

    bool growing = 1;
    unordered_set<int> s;
    int total_size = 0, towers_count = 0, last = 0;

    for (int i = 0; i < N; i++) {
        if (s.empty()) {
            towers_count++;
            total_size += boxS[i];
            last = boxS[i];
            s.insert(boxS[i]);
            continue;
        }

        if (total_size + boxS[i] > M || has(s, boxS[i]) || (!growing  && boxS[i] > last)) {
            growing = 1;
            s.clear();
            total_size = 0;
            i--; // a következő iterációban fogunk foglalkozni az elemmel újra
            continue;
        }

        if (boxS[i] < last) {
            growing = 0;
        }

        last = boxS[i];
        total_size += boxS[i];
        s.insert(boxS[i]);
    }

    cout << N - towers_count;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/04ms2196 KiB
3Accepted2/23ms2276 KiB
4Accepted2/23ms2492 KiB
5Accepted2/23ms2708 KiB
6Accepted2/23ms2920 KiB
7Accepted2/23ms3152 KiB
8Accepted2/23ms3372 KiB
9Accepted3/33ms3576 KiB
10Accepted2/23ms3656 KiB
11Accepted2/23ms3664 KiB
12Accepted2/23ms3684 KiB
13Accepted3/34ms4032 KiB
14Accepted3/34ms4032 KiB
15Accepted3/34ms4124 KiB
16Accepted2/220ms5084 KiB
17Accepted3/323ms6016 KiB
18Accepted3/327ms7148 KiB
19Accepted3/323ms7672 KiB
20Accepted3/323ms11100 KiB
21Accepted3/356ms11476 KiB
22Accepted3/339ms12860 KiB