10546 | 2024-04-04 22:12:49 | 111 | Az IKPC legerősebb csapata | cpp17 | Wrong answer 18/100 | 32ms | 11248 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>>g(N+1);
vector<int>s;
for(int i=N;i>=1;i--){
while(!s.empty()&&a[s.back()]<=a[i]){
s.pop_back();
}
g[s.empty()?0:s.back()].push_back(i);
s.push_back(i);
}
auto dfs=[&](auto self,int i)->vector<int>{
vector<int>s;
for(int j:g[i]){
auto z=self(self,j);
if(s.size()<z.size()){
swap(s,z);
}
s.insert(s.end(),z.begin(),z.end());
}
sort(s.begin(),s.end());
if(s.empty()){
s.push_back(b[i]);
}
else{
s.back()+=b[i];
}
return s;
};
auto ans=dfs(dfs,0);
cout<<accumulate(max(ans.begin(),ans.end()-K),ans.end(),0ll)<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Wrong answer | 3ms | 2284 KiB | ||||
4 | Wrong answer | 3ms | 2644 KiB | ||||
5 | Wrong answer | 3ms | 2388 KiB | ||||
6 | Wrong answer | 3ms | 2572 KiB | ||||
7 | Wrong answer | 3ms | 2788 KiB | ||||
8 | Wrong answer | 3ms | 3000 KiB | ||||
9 | Wrong answer | 3ms | 3208 KiB | ||||
10 | Wrong answer | 3ms | 3288 KiB | ||||
11 | Wrong answer | 3ms | 3524 KiB | ||||
12 | Wrong answer | 3ms | 3596 KiB | ||||
subtask3 | 7/7 | ||||||
13 | Accepted | 3ms | 3664 KiB | ||||
14 | Accepted | 3ms | 3984 KiB | ||||
15 | Accepted | 4ms | 4216 KiB | ||||
16 | Accepted | 4ms | 4344 KiB | ||||
17 | Accepted | 4ms | 4424 KiB | ||||
18 | Accepted | 4ms | 4312 KiB | ||||
19 | Accepted | 4ms | 4320 KiB | ||||
20 | Accepted | 4ms | 4372 KiB | ||||
21 | Accepted | 4ms | 4412 KiB | ||||
subtask4 | 11/11 | ||||||
22 | Accepted | 27ms | 10584 KiB | ||||
23 | Accepted | 28ms | 10532 KiB | ||||
24 | Accepted | 29ms | 10528 KiB | ||||
25 | Accepted | 30ms | 10812 KiB | ||||
26 | Accepted | 30ms | 10792 KiB | ||||
27 | Accepted | 32ms | 10716 KiB | ||||
subtask5 | 0/22 | ||||||
28 | Wrong answer | 4ms | 4604 KiB | ||||
29 | Wrong answer | 4ms | 4724 KiB | ||||
30 | Wrong answer | 4ms | 4964 KiB | ||||
31 | Wrong answer | 4ms | 4944 KiB | ||||
32 | Wrong answer | 4ms | 5048 KiB | ||||
33 | Wrong answer | 4ms | 5040 KiB | ||||
34 | Wrong answer | 4ms | 5128 KiB | ||||
subtask6 | 0/51 | ||||||
35 | Wrong answer | 28ms | 11248 KiB | ||||
36 | Wrong answer | 28ms | 11132 KiB | ||||
37 | Wrong answer | 29ms | 11020 KiB | ||||
38 | Wrong answer | 30ms | 11032 KiB | ||||
39 | Wrong answer | 30ms | 11028 KiB | ||||
40 | Wrong answer | 32ms | 11028 KiB | ||||
41 | Wrong answer | 32ms | 11032 KiB | ||||
42 | Accepted | 32ms | 11024 KiB | ||||
43 | Accepted | 32ms | 11028 KiB | ||||
44 | Wrong answer | 32ms | 11024 KiB | ||||
45 | Wrong answer | 32ms | 11020 KiB |