12352022-03-27 18:41:28Valaki2Növekvő Ödön és a Másoló Varázslócpp14Runtime error 20/100603ms488992 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int inf = 1e9 + 7;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(1 + n, 0);
    vector<int> b(1 + n, 0);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    sort(b.begin() + 1, b.end());
    vector<int> req(1 + n, inf);
    // req[i]: minimum hany valtoztatas kell mindenkepp (az elso i elemen ertelmezve)
    vector<vector<int> > dp(1 + n, vector<int> (1 + n, inf));
    // dp[i][j]: max j darab valtoztatassal mi a legkisebb maximum (az elso i elemen ertelmezve)
    // dp[i] csokkeno
    for(int j = 0; j <= n; j++) {
        dp[0][j] = 0;
    }
    req[0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = req[i - 1]; j <= n; j++) {
            if(dp[i - 1][j] < a[i]) {
                dp[i][j] = a[i];
            }
        }
        for(int j = req[i - 1]; j < n; j++) {
            auto it = upper_bound(b.begin(), b.end(), dp[i - 1][j]);
            if(it == b.end()) {
                continue;
            }
            int num = *it;
            dp[i][j + 1] = min(dp[i][j + 1], num);
        }
        for(int j = 0; j <= n; j++) {
            if(dp[i][j] != inf) {
                req[i] = j;
                break;
            }
        }
    }
    cout << req[n] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1936 KiB
2Runtime error282ms444332 KiB
subtask20/5
3Runtime error4ms2568 KiB
4Runtime error4ms3096 KiB
5Runtime error4ms3588 KiB
subtask310/10
6Accepted1ms3372 KiB
7Accepted1ms3372 KiB
8Accepted1ms3380 KiB
subtask40/15
9Accepted3ms4088 KiB
10Accepted4ms4096 KiB
11Runtime error2ms3524 KiB
12Accepted3ms4116 KiB
subtask55/5
13Accepted374ms199380 KiB
14Accepted356ms199432 KiB
15Accepted363ms199536 KiB
subtask65/5
16Accepted363ms199636 KiB
17Accepted375ms199704 KiB
18Accepted358ms199832 KiB
19Accepted360ms199936 KiB
subtask70/10
20Time limit exceeded603ms200004 KiB
21Accepted564ms200104 KiB
22Accepted379ms200204 KiB
23Accepted196ms75020 KiB
24Runtime error3ms4736 KiB
subtask80/25
25Runtime error356ms456616 KiB
26Runtime error261ms456684 KiB
27Runtime error261ms457024 KiB
28Accepted1ms1900 KiB
29Runtime error259ms456988 KiB
30Runtime error240ms456244 KiB
31Runtime error244ms453936 KiB
32Runtime error247ms456884 KiB
33Runtime error263ms470180 KiB
34Runtime error256ms477024 KiB
35Runtime error248ms483016 KiB
36Runtime error270ms483424 KiB
37Runtime error307ms483152 KiB
38Runtime error317ms482864 KiB
39Runtime error266ms486844 KiB
40Runtime error256ms485336 KiB
41Runtime error256ms488992 KiB
42Runtime error250ms483396 KiB
43Runtime error248ms456968 KiB
44Runtime error252ms448812 KiB
45Runtime error240ms457548 KiB
subtask90/25
46Runtime error300ms482920 KiB
47Runtime error286ms399692 KiB
48Runtime error328ms472920 KiB
49Runtime error280ms461448 KiB
50Runtime error293ms482460 KiB
51Runtime error284ms457584 KiB
52Runtime error284ms473784 KiB
53Runtime error268ms456416 KiB
54Runtime error305ms475152 KiB
55Runtime error282ms466392 KiB