105452024-04-04 20:25:38111Az IKPC legerősebb csapatacpp17Wrong answer 0/100448ms1046868 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,K;
	cin>>N>>K;
	vector<int>a(N+1),b(N+1);
	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	for(int i=1;i<=N;i++){
		cin>>b[i];
	}
	vector<vector<int>>dp0(K+1,vector<int>(N+1,0)),dp1(K+1,vector<int>(N+1,0));
	for(int i=1;i<=K;i++){
		for(int j=1;j<=N;j++){
			dp0[i][j]=max(dp0[i][j-1],dp0[i-1][j]);
			dp0[i][j]=max(dp0[i][j],dp0[i-1][j-1]+b[j]);
			dp1[i][j]=max(dp1[i][j],dp0[i-1][j-1]+b[j]);
			if(a[j-1]<a[j]){
				dp1[i][j]=max(dp1[i][j],dp1[i][j-1]+b[j]);
			}
			for(int k=j-1;k>=0&&a[k]<a[j];k--){
				dp1[i][j]=max(dp1[i][j],dp1[i][k]+b[j]);
				if(k>=2&&a[k-1]<a[k]){
					break;
				}
			}
			dp0[i][j]=max(dp0[i][j],dp1[i][j]);
		}
	}
	cout<<dp0[K][N]<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1976 KiB
2Accepted3ms2196 KiB
subtask20/9
3Accepted2ms2208 KiB
4Wrong answer2ms2132 KiB
5Wrong answer3ms2260 KiB
6Accepted2ms2296 KiB
7Accepted3ms2424 KiB
8Wrong answer3ms2664 KiB
9Wrong answer3ms2892 KiB
10Accepted2ms2972 KiB
11Wrong answer3ms3104 KiB
12Wrong answer3ms3324 KiB
subtask30/7
13Accepted10ms19460 KiB
14Wrong answer10ms17576 KiB
15Wrong answer32ms54376 KiB
16Accepted128ms216876 KiB
17Accepted172ms292776 KiB
18Accepted86ms146588 KiB
19Accepted86ms146872 KiB
20Wrong answer9ms15468 KiB
21Accepted305ms506648 KiB
subtask40/11
22Runtime error358ms1046868 KiB
23Runtime error360ms1046856 KiB
24Runtime error358ms1046832 KiB
25Runtime error442ms1046596 KiB
26Runtime error360ms1046572 KiB
27Runtime error363ms1046568 KiB
subtask50/22
28Wrong answer54ms91264 KiB
29Accepted97ms142480 KiB
30Accepted89ms147272 KiB
31Wrong answer158ms259920 KiB
32Wrong answer28ms48300 KiB
33Wrong answer134ms228708 KiB
34Wrong answer13ms21388 KiB
subtask60/51
35Runtime error363ms1046380 KiB
36Runtime error365ms1046356 KiB
37Runtime error448ms1046124 KiB
38Runtime error365ms1046124 KiB
39Runtime error365ms1046116 KiB
40Runtime error361ms1046116 KiB
41Runtime error365ms1046120 KiB
42Runtime error363ms1046076 KiB
43Runtime error363ms1046076 KiB
44Runtime error361ms1046100 KiB
45Runtime error363ms1046104 KiB