80672024-01-12 11:50:38gkataLádapakolás raktárban (50)cpp17Accepted 50/5057ms10816 KiB
// ladapakolas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <map>
#define ll long long

using namespace std;

map<ll, ll>st;

ll db, i, n, m, s;

int main()
{
    cin >> n >> m;

    vector<ll>x(n + 1);

    for (i = 1; i <= n; ++i) cin >> x[i];

    i = 1;
    while (i <= n)
    {
        st.clear();
        s = x[i];
        st[x[i]] = 1;
        ++i;

        while (i <= n && x[i - 1] < x[i] && s + x[i] <= m)
        {
            s += x[i];
            st[x[i]] = 1;
            ++i;
            ++db;
        }
        while (i <= n && x[i - 1] > x[i] && s + x[i] <= m && st[x[i]] != 1)
        {
            s += x[i];
            ++i;
            ++db;
        }
    }

    cout << db;
}

/*
12 16
1 3 5 4 2 6 8 7 6 5 3 4
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1684 KiB
2Accepted0/06ms2048 KiB
3Accepted2/23ms2060 KiB
4Accepted2/23ms2304 KiB
5Accepted2/23ms2512 KiB
6Accepted2/23ms2764 KiB
7Accepted2/23ms2944 KiB
8Accepted2/23ms3160 KiB
9Accepted3/33ms3396 KiB
10Accepted2/23ms3516 KiB
11Accepted2/23ms3760 KiB
12Accepted2/24ms3884 KiB
13Accepted3/34ms4116 KiB
14Accepted3/34ms4096 KiB
15Accepted3/37ms4364 KiB
16Accepted2/235ms5596 KiB
17Accepted3/346ms5680 KiB
18Accepted3/357ms5768 KiB
19Accepted3/339ms5696 KiB
20Accepted3/352ms10008 KiB
21Accepted3/346ms9776 KiB
22Accepted3/350ms10816 KiB