10038 | 2024-03-25 16:44:19 | 111 | Növekvő Ödön és a Másoló Varázsló | cpp17 | Runtime error 50/100 | 230ms | 395748 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
if(N*M>100000000){
return 1;
}
vector<int>v(N+1),w(M);
for(int i=1;i<=N;i++){
cin>>v[i];
}
for(int i=0;i<M;i++){
cin>>w[i];
}
sort(w.begin(),w.end());
vector<vector<int>>dp(N+1,vector<int>(M));
vector<int>ans(N+1);
for(int i=1;i<=N;i++){
for(int j=0;j<M;j++){
dp[i][j]=j==0?N*2:dp[i-1][j-1]+1;
if(w[j]>v[i-1]){
dp[i][j]=min(dp[i][j],ans[i-1]+1);
}
}
int j=upper_bound(w.begin(),w.end(),v[i])-w.begin();
ans[i]=N*2;
if(j>0){
ans[i]=min(ans[i],dp[i][j-1]);
}
if(j>0){
ans[i]=min(ans[i],dp[i-1][j-1]);
}
if(v[i]>v[i-1]){
ans[i]=min(ans[i],ans[i-1]);
}
}
// for(int i=1;i<=N;i++){
// cout<<setw(4)<<ans[i]<<" | ";
// for(int j=i-1;j<M;j++){
// cout<<setw(4)<<dp[i][j]<<' ';
// }
// cout<<'\n';
// }
cout<<min(ans[N],*min_element(dp[N].begin(),dp[N].end()))<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Runtime error | 3ms | 2168 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 59ms | 18012 KiB | ||||
4 | Accepted | 61ms | 18132 KiB | ||||
5 | Accepted | 59ms | 18344 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 3ms | 2888 KiB | ||||
7 | Accepted | 2ms | 2976 KiB | ||||
8 | Accepted | 3ms | 3104 KiB | ||||
subtask4 | 15/15 | ||||||
9 | Accepted | 4ms | 4560 KiB | ||||
10 | Accepted | 4ms | 4788 KiB | ||||
11 | Accepted | 3ms | 4444 KiB | ||||
12 | Accepted | 3ms | 4740 KiB | ||||
subtask5 | 5/5 | ||||||
13 | Accepted | 196ms | 394900 KiB | ||||
14 | Accepted | 230ms | 395160 KiB | ||||
15 | Accepted | 196ms | 395176 KiB | ||||
subtask6 | 5/5 | ||||||
16 | Accepted | 187ms | 395456 KiB | ||||
17 | Accepted | 181ms | 395516 KiB | ||||
18 | Accepted | 190ms | 395536 KiB | ||||
19 | Accepted | 179ms | 395488 KiB | ||||
subtask7 | 10/10 | ||||||
20 | Accepted | 224ms | 395748 KiB | ||||
21 | Accepted | 188ms | 395704 KiB | ||||
22 | Accepted | 187ms | 395640 KiB | ||||
23 | Accepted | 70ms | 145188 KiB | ||||
24 | Accepted | 178ms | 376756 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Runtime error | 3ms | 4276 KiB | ||||
26 | Runtime error | 2ms | 4276 KiB | ||||
27 | Runtime error | 2ms | 4276 KiB | ||||
28 | Accepted | 2ms | 4268 KiB | ||||
29 | Runtime error | 2ms | 4272 KiB | ||||
30 | Runtime error | 3ms | 4504 KiB | ||||
31 | Runtime error | 3ms | 4512 KiB | ||||
32 | Runtime error | 2ms | 4508 KiB | ||||
33 | Runtime error | 2ms | 4512 KiB | ||||
34 | Runtime error | 2ms | 4512 KiB | ||||
35 | Runtime error | 3ms | 4712 KiB | ||||
36 | Runtime error | 2ms | 4812 KiB | ||||
37 | Runtime error | 2ms | 4800 KiB | ||||
38 | Runtime error | 2ms | 4700 KiB | ||||
39 | Runtime error | 3ms | 4700 KiB | ||||
40 | Runtime error | 2ms | 4696 KiB | ||||
41 | Runtime error | 2ms | 4700 KiB | ||||
42 | Runtime error | 2ms | 4700 KiB | ||||
43 | Runtime error | 2ms | 4804 KiB | ||||
44 | Runtime error | 2ms | 4796 KiB | ||||
45 | Runtime error | 3ms | 5020 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Runtime error | 3ms | 5124 KiB | ||||
47 | Runtime error | 2ms | 5024 KiB | ||||
48 | Runtime error | 3ms | 5104 KiB | ||||
49 | Runtime error | 3ms | 5108 KiB | ||||
50 | Runtime error | 3ms | 5204 KiB | ||||
51 | Runtime error | 3ms | 5172 KiB | ||||
52 | Runtime error | 3ms | 5180 KiB | ||||
53 | Runtime error | 2ms | 5180 KiB | ||||
54 | Runtime error | 3ms | 5172 KiB | ||||
55 | Runtime error | 3ms | 4972 KiB |