11012022-03-02 21:31:55peti1234Vállalkozócpp14Accepted 40/4017ms5264 KiB
#include <bits/stdc++.h>

using namespace std;
int n, m, valasz;
priority_queue<int>q;
vector<int> h;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        int x;
        cin >> x;
        for (int j=1; j<=x; j++) {
            q.push(i);
        }
    }
    // q-ban a szabad orak, novekvo sorrendben (a nap szerint)

    for (int i=1; i<=m; i++) {
        int x;
        cin >> x;
        h.push_back(x);
    }
    sort(h.rbegin(), h.rend());
    // h-ban vannak a hataridok novekvo sorrendben

    for (auto x:h) {
        //cout << "fontos " << x << "\n";
        while (q.size()>0 && q.top()>x) {
            q.pop();
        }
        if (q.size()>0) {
            // mukodik a moho strategia, ha meg lehet csinalni a legsurgosebb munkat, akkor erdemes
            valasz++;
            q.pop();
        }
    }
    cout << valasz << "\n";
    return 0;
}
/*
5 7
0 0 3 0 5
1 2 3 4 5 6 7
*/
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1816 KiB
2Accepted0/017ms3600 KiB
3Accepted2/21ms2304 KiB
4Accepted2/21ms2308 KiB
5Accepted2/22ms2308 KiB
6Accepted2/22ms2360 KiB
7Accepted2/22ms2404 KiB
8Accepted2/21ms2388 KiB
9Accepted2/22ms2420 KiB
10Accepted2/21ms2396 KiB
11Accepted2/22ms2440 KiB
12Accepted2/22ms2440 KiB
13Accepted2/22ms2484 KiB
14Accepted2/22ms2512 KiB
15Accepted2/26ms2984 KiB
16Accepted2/26ms2952 KiB
17Accepted2/27ms3636 KiB
18Accepted2/24ms3432 KiB
19Accepted2/26ms3568 KiB
20Accepted2/28ms4136 KiB
21Accepted2/213ms4868 KiB
22Accepted2/217ms5264 KiB