100382024-03-25 16:44:19111Növekvő Ödön és a Másoló Varázslócpp17Runtime error 50/100230ms395748 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Runtime error3ms2168 KiB
subtask25/5
3Accepted59ms18012 KiB
4Accepted61ms18132 KiB
5Accepted59ms18344 KiB
subtask310/10
6Accepted3ms2888 KiB
7Accepted2ms2976 KiB
8Accepted3ms3104 KiB
subtask415/15
9Accepted4ms4560 KiB
10Accepted4ms4788 KiB
11Accepted3ms4444 KiB
12Accepted3ms4740 KiB
subtask55/5
13Accepted196ms394900 KiB
14Accepted230ms395160 KiB
15Accepted196ms395176 KiB
subtask65/5
16Accepted187ms395456 KiB
17Accepted181ms395516 KiB
18Accepted190ms395536 KiB
19Accepted179ms395488 KiB
subtask710/10
20Accepted224ms395748 KiB
21Accepted188ms395704 KiB
22Accepted187ms395640 KiB
23Accepted70ms145188 KiB
24Accepted178ms376756 KiB
subtask80/25
25Runtime error3ms4276 KiB
26Runtime error2ms4276 KiB
27Runtime error2ms4276 KiB
28Accepted2ms4268 KiB
29Runtime error2ms4272 KiB
30Runtime error3ms4504 KiB
31Runtime error3ms4512 KiB
32Runtime error2ms4508 KiB
33Runtime error2ms4512 KiB
34Runtime error2ms4512 KiB
35Runtime error3ms4712 KiB
36Runtime error2ms4812 KiB
37Runtime error2ms4800 KiB
38Runtime error2ms4700 KiB
39Runtime error3ms4700 KiB
40Runtime error2ms4696 KiB
41Runtime error2ms4700 KiB
42Runtime error2ms4700 KiB
43Runtime error2ms4804 KiB
44Runtime error2ms4796 KiB
45Runtime error3ms5020 KiB
subtask90/25
46Runtime error3ms5124 KiB
47Runtime error2ms5024 KiB
48Runtime error3ms5104 KiB
49Runtime error3ms5108 KiB
50Runtime error3ms5204 KiB
51Runtime error3ms5172 KiB
52Runtime error3ms5180 KiB
53Runtime error2ms5180 KiB
54Runtime error3ms5172 KiB
55Runtime error3ms4972 KiB