100372024-03-25 16:32:38111Növekvő Ödön és a Másoló Varázslócpp17Runtime error 50/100307ms402184 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]+!(v[i-1]<v[i]&&v[i]<w[j]));
			}
		}
		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:dp[i]){
			// cout<<setw(4)<<j<<' ';
		// }
		// cout<<'\n';
	// }
	cout<<min(ans[N],*min_element(dp[N].begin(),dp[N].end()))<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Runtime error3ms2056 KiB
subtask25/5
3Accepted64ms19832 KiB
4Accepted61ms22012 KiB
5Accepted59ms23888 KiB
subtask310/10
6Accepted3ms8340 KiB
7Accepted3ms8580 KiB
8Accepted3ms8748 KiB
subtask415/15
9Accepted3ms10036 KiB
10Accepted4ms10300 KiB
11Accepted4ms9816 KiB
12Accepted4ms10464 KiB
subtask55/5
13Accepted272ms400648 KiB
14Accepted305ms401052 KiB
15Accepted307ms401332 KiB
subtask65/5
16Accepted279ms401364 KiB
17Accepted219ms401628 KiB
18Accepted293ms401600 KiB
19Accepted248ms401812 KiB
subtask710/10
20Accepted279ms401952 KiB
21Accepted243ms402040 KiB
22Accepted239ms402184 KiB
23Accepted104ms151948 KiB
24Accepted264ms383420 KiB
subtask80/25
25Runtime error3ms11208 KiB
26Runtime error2ms11288 KiB
27Runtime error3ms11364 KiB
28Accepted3ms11364 KiB
29Runtime error3ms11364 KiB
30Runtime error3ms11364 KiB
31Runtime error3ms11496 KiB
32Runtime error3ms11620 KiB
33Runtime error3ms11720 KiB
34Runtime error3ms11704 KiB
35Runtime error3ms11688 KiB
36Runtime error3ms11812 KiB
37Runtime error3ms11808 KiB
38Runtime error3ms11792 KiB
39Runtime error2ms11692 KiB
40Runtime error3ms11692 KiB
41Runtime error3ms11788 KiB
42Runtime error3ms11780 KiB
43Runtime error3ms11916 KiB
44Runtime error3ms12000 KiB
45Runtime error3ms12004 KiB
subtask90/25
46Runtime error3ms12000 KiB
47Runtime error2ms12000 KiB
48Runtime error3ms12096 KiB
49Runtime error2ms12104 KiB
50Runtime error2ms12204 KiB
51Runtime error2ms12104 KiB
52Runtime error2ms12100 KiB
53Runtime error2ms12004 KiB
54Runtime error3ms12100 KiB
55Runtime error2ms12200 KiB