10561 | 2024-04-05 13:43:14 | 111 | Az IKPC legerősebb csapata | cpp17 | Wrong answer 0/100 | 1.082s | 6616 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,K;
cin>>N>>K;
vector<int>v(N+1),w(N+1);
for(int i=1;i<=N;i++){
cin>>v[i];
}
for(int i=1;i<=N;i++){
cin>>w[i];
}
vector<vector<int>>g(N+1);
vector<int>s;
for(int i=N;i>=1;i--){
while(!s.empty()&&v[s.back()]<=v[i]){
s.pop_back();
}
g[s.empty()?0:s.back()].push_back(i);
s.push_back(i);
}
auto solveMin=[&](int y)->pii{
auto dfs=[&](auto self,int i)->pair<pii,pii>{
pii a{},b{};
for(int j:g[i]){
auto [p,q]=self(self,j);
a.first+=p.first;
a.second+=p.second;
if(q.first-p.first>b.first){
b.first=q.first-p.first;
b.second=q.second-p.second;
}
}
b.first+=a.first+w[i];
b.second+=a.second;
if(w[i]>y){
a.first+=w[i]-y;
a.second++;
}
if(b.first-y>a.first){
a.first=b.first-y;
a.second=b.second+1;
}
return{a,b};
};
return dfs(dfs,0).first;
};
auto solveMax=[&](int y)->pii{
auto dfs=[&](auto self,int i)->pair<pii,pii>{
pii a{},b{};
for(int j:g[i]){
auto [p,q]=self(self,j);
a.first+=p.first;
a.second+=p.second;
if(q.first-p.first>b.first||q.first-p.first==b.first&&q.second-p.second>b.second){
b.first=q.first-p.first;
b.second=q.second-p.second;
}
}
b.first+=a.first+w[i];
b.second+=a.second;
if(b.first-y>=a.first){
a.first=b.first-y;
a.second=b.second+1;
}
return{a,b};
};
return dfs(dfs,0).first;
};
int ans=0;
for(int i=0;i<200000;i++){
auto[x,c]=solveMin(i);
auto[x2,c2]=solveMax(i);
if(x!=x2)exit(1);
if(c<=K)ans=max(ans,x+min(K,c2)*i);
}
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 20ms | 1760 KiB | ||||
2 | Accepted | 30ms | 1864 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Accepted | 37ms | 1948 KiB | ||||
4 | Wrong answer | 56ms | 2172 KiB | ||||
5 | Wrong answer | 54ms | 2512 KiB | ||||
6 | Accepted | 54ms | 2600 KiB | ||||
7 | Accepted | 54ms | 2732 KiB | ||||
8 | Wrong answer | 54ms | 2808 KiB | ||||
9 | Wrong answer | 54ms | 2876 KiB | ||||
10 | Accepted | 68ms | 3004 KiB | ||||
11 | Wrong answer | 59ms | 3108 KiB | ||||
12 | Wrong answer | 54ms | 3108 KiB | ||||
subtask3 | 0/7 | ||||||
13 | Time limit exceeded | 1.024s | 3452 KiB | ||||
14 | Time limit exceeded | 1.041s | 3868 KiB | ||||
15 | Time limit exceeded | 1.049s | 3008 KiB | ||||
16 | Time limit exceeded | 1.049s | 3944 KiB | ||||
17 | Time limit exceeded | 1.057s | 3052 KiB | ||||
18 | Time limit exceeded | 1.049s | 4208 KiB | ||||
19 | Time limit exceeded | 1.052s | 4416 KiB | ||||
20 | Time limit exceeded | 1.057s | 3380 KiB | ||||
21 | Time limit exceeded | 1.057s | 3536 KiB | ||||
subtask4 | 0/11 | ||||||
22 | Time limit exceeded | 1.057s | 6196 KiB | ||||
23 | Time limit exceeded | 1.074s | 6216 KiB | ||||
24 | Time limit exceeded | 1.074s | 6196 KiB | ||||
25 | Time limit exceeded | 1.065s | 6284 KiB | ||||
26 | Time limit exceeded | 1.074s | 6244 KiB | ||||
27 | Time limit exceeded | 1.057s | 6380 KiB | ||||
subtask5 | 0/22 | ||||||
28 | Time limit exceeded | 1.049s | 3372 KiB | ||||
29 | Time limit exceeded | 1.072s | 4380 KiB | ||||
30 | Time limit exceeded | 1.069s | 3380 KiB | ||||
31 | Time limit exceeded | 1.049s | 3496 KiB | ||||
32 | Time limit exceeded | 1.036s | 3492 KiB | ||||
33 | Time limit exceeded | 1.077s | 3520 KiB | ||||
34 | Time limit exceeded | 1.052s | 4476 KiB | ||||
subtask6 | 0/51 | ||||||
35 | Time limit exceeded | 1.057s | 6328 KiB | ||||
36 | Time limit exceeded | 1.069s | 6240 KiB | ||||
37 | Time limit exceeded | 1.065s | 6376 KiB | ||||
38 | Time limit exceeded | 1.074s | 6300 KiB | ||||
39 | Time limit exceeded | 1.054s | 6392 KiB | ||||
40 | Time limit exceeded | 1.062s | 6408 KiB | ||||
41 | Time limit exceeded | 1.077s | 6596 KiB | ||||
42 | Time limit exceeded | 1.065s | 6616 KiB | ||||
43 | Time limit exceeded | 1.054s | 6572 KiB | ||||
44 | Time limit exceeded | 1.065s | 6576 KiB | ||||
45 | Time limit exceeded | 1.082s | 6516 KiB |