80662024-01-12 11:48:59gkataLádapakolás raktárban (50)cpp17Hibás válasz 42/5059ms15480 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base42/50
1Elfogadva0/03ms1808 KiB
2Hibás válasz0/06ms2264 KiB
3Elfogadva2/23ms2304 KiB
4Elfogadva2/23ms2376 KiB
5Elfogadva2/23ms2580 KiB
6Elfogadva2/23ms2792 KiB
7Elfogadva2/23ms2912 KiB
8Elfogadva2/23ms3000 KiB
9Elfogadva3/33ms3140 KiB
10Elfogadva2/23ms3220 KiB
11Elfogadva2/23ms3352 KiB
12Elfogadva2/24ms3352 KiB
13Elfogadva3/34ms3456 KiB
14Hibás válasz0/34ms3632 KiB
15Elfogadva3/37ms3816 KiB
16Hibás válasz0/235ms5260 KiB
17Hibás válasz0/346ms6240 KiB
18Elfogadva3/359ms7352 KiB
19Elfogadva3/339ms7872 KiB
20Elfogadva3/352ms12908 KiB
21Elfogadva3/346ms13552 KiB
22Elfogadva3/350ms15480 KiB