12362022-03-27 18:43:59Valaki2Növekvő Ödön és a Másoló Varázslócpp14Runtime error 50/100598ms473728 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 + m, 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
1Accepted2ms2028 KiB
2Runtime error241ms445392 KiB
subtask25/5
3Accepted45ms5216 KiB
4Accepted43ms7156 KiB
5Accepted41ms9112 KiB
subtask310/10
6Accepted1ms7756 KiB
7Accepted1ms7760 KiB
8Accepted1ms7784 KiB
subtask415/15
9Accepted3ms8476 KiB
10Accepted3ms8480 KiB
11Accepted2ms8184 KiB
12Accepted2ms8496 KiB
subtask55/5
13Accepted363ms202392 KiB
14Accepted361ms198848 KiB
15Accepted361ms198952 KiB
subtask65/5
16Accepted358ms199088 KiB
17Accepted363ms199244 KiB
18Accepted365ms199304 KiB
19Accepted360ms199384 KiB
subtask710/10
20Accepted598ms199476 KiB
21Accepted555ms199564 KiB
22Accepted374ms199664 KiB
23Accepted167ms74480 KiB
24Accepted483ms181244 KiB
subtask80/25
25Runtime error240ms456312 KiB
26Runtime error246ms456504 KiB
27Runtime error248ms456488 KiB
28Accepted1ms1948 KiB
29Runtime error273ms455672 KiB
30Runtime error250ms456292 KiB
31Runtime error250ms457752 KiB
32Runtime error259ms461436 KiB
33Runtime error259ms469896 KiB
34Runtime error263ms473716 KiB
35Runtime error246ms473728 KiB
36Runtime error247ms471836 KiB
37Runtime error248ms473032 KiB
38Runtime error256ms473020 KiB
39Runtime error257ms472816 KiB
40Runtime error254ms473092 KiB
41Runtime error261ms472864 KiB
42Runtime error239ms473344 KiB
43Runtime error261ms472972 KiB
44Runtime error245ms470276 KiB
45Runtime error250ms473080 KiB
subtask90/25
46Runtime error282ms473116 KiB
47Runtime error284ms472916 KiB
48Runtime error397ms471540 KiB
49Runtime error284ms472944 KiB
50Runtime error305ms470664 KiB
51Runtime error284ms473508 KiB
52Runtime error272ms473092 KiB
53Runtime error284ms473424 KiB
54Runtime error282ms473696 KiB
55Runtime error289ms473136 KiB