162192025-04-14 17:53:09Error42Növekvő Ödön és a Másoló Varázslócpp17Runtime error 5/100680ms1992 KiB
#include <algorithm>
#include <cassert>
#include <iostream>
#include <variant>
#include <vector>

using namespace std;

int const INF = 2e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    for (int& x : a)
        cin >> x;

    a.insert(a.begin(), 0);
    a.push_back(INF);

    vector<int> b(m);
    for (int& x : b)
        cin >> x;

    sort(b.begin(), b.end());

    int lis_max_len = 0;
    vector<int> lis = { 0 };

    for (int j = 1; j < a.size(); j++) {
        auto it = find_if_not(lis.rbegin(), lis.rend(), [&](int const& i) {
#ifdef _DEBUG
            cerr << i << " " << j
                << " : " << a[i] << ">=" << a[j]
                << " | " << lower_bound(b.begin(), b.end(), a[j]) - lower_bound(b.begin(), b.end(), a[i]) + 1 << "<" << j - i << endl;
#endif

            return a[i] >= a[j] // not increasing
                || lower_bound(b.begin(), b.end(), a[j]) - lower_bound(b.begin(), b.end(), a[i]) + 1 < j - i; // not enough elements to put between
        });

        if (it == lis.rend())
            continue;

        if (it == lis.rbegin())
            lis.push_back(j);
        else
            *(it + 1) = j;
    }

#ifdef _DEBUG
    assert(count(lis.begin(), lis.end(), n + 1));
#endif

    cout << n - (find(lis.begin(), lis.end(), n + 1) - lis.begin() - 1) << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Runtime error32ms880 KiB
subtask20/5
3Accepted50ms1076 KiB
4Accepted50ms1076 KiB
5Runtime error50ms1220 KiB
subtask30/10
6Runtime error1ms316 KiB
7Runtime error1ms316 KiB
8Runtime error1ms316 KiB
subtask40/15
9Runtime error1ms508 KiB
10Runtime error1ms320 KiB
11Runtime error1ms316 KiB
12Runtime error1ms316 KiB
subtask55/5
13Accepted3ms316 KiB
14Accepted3ms500 KiB
15Accepted3ms316 KiB
subtask60/5
16Runtime error3ms316 KiB
17Wrong answer4ms316 KiB
18Wrong answer3ms316 KiB
19Runtime error3ms316 KiB
subtask70/10
20Wrong answer16ms508 KiB
21Runtime error3ms316 KiB
22Runtime error3ms448 KiB
23Runtime error2ms316 KiB
24Runtime error3ms316 KiB
subtask80/25
25Runtime error50ms1388 KiB
26Runtime error48ms1196 KiB
27Runtime error48ms1192 KiB
28Accepted1ms316 KiB
29Runtime error46ms1204 KiB
30Wrong answer393ms1220 KiB
31Runtime error529ms1216 KiB
32Runtime error41ms1192 KiB
33Runtime error68ms1196 KiB
34Runtime error45ms1196 KiB
35Runtime error39ms1196 KiB
36Time limit exceeded671ms1208 KiB
37Runtime error148ms1200 KiB
38Runtime error39ms1196 KiB
39Runtime error41ms1196 KiB
40Wrong answer48ms1204 KiB
41Runtime error72ms1200 KiB
42Wrong answer37ms1060 KiB
43Time limit exceeded680ms1204 KiB
44Runtime error71ms1196 KiB
45Runtime error39ms1200 KiB
subtask90/25
46Time limit exceeded674ms1844 KiB
47Runtime error81ms1992 KiB
48Time limit exceeded674ms1848 KiB
49Runtime error82ms1984 KiB
50Runtime error81ms1992 KiB
51Runtime error79ms1984 KiB
52Runtime error98ms1712 KiB
53Runtime error119ms1920 KiB
54Runtime error128ms1988 KiB
55Runtime error101ms1976 KiB