10554 | 2024-04-05 13:03:21 | 111 | Az IKPC legerősebb csapata | cpp17 | Wrong answer 0/100 | 114ms | 10312 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 solve=[&](int y)->pii{
auto dfs=[&](auto self,int i)->pair<pii,pii>{
pii a{},b{},c{};
for(int j:g[i]){
auto [p,q]=self(self,j);
a.first+=p.first;
a.second+=p.second;
if(q.first>b.first){
b=q;
c=p;
}
}
b.first+=a.first-c.first+w[i];
b.second+=a.second-c.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;
};
int l=0,h=1e16;
while(l<h){
int m=(l+h)/2;
auto[x,c]=solve(m);
if(c<K){
h=m;
}
else{
l=m+1;
}
}
auto[x,c]=solve(h);
cout<<x+K*h<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2060 KiB | ||||
subtask2 | 0/9 | ||||||
3 | Accepted | 3ms | 2268 KiB | ||||
4 | Wrong answer | 3ms | 2496 KiB | ||||
5 | Wrong answer | 3ms | 2656 KiB | ||||
6 | Accepted | 3ms | 2864 KiB | ||||
7 | Accepted | 3ms | 2952 KiB | ||||
8 | Wrong answer | 3ms | 2952 KiB | ||||
9 | Wrong answer | 3ms | 2956 KiB | ||||
10 | Accepted | 3ms | 2964 KiB | ||||
11 | Wrong answer | 3ms | 3108 KiB | ||||
12 | Wrong answer | 3ms | 3092 KiB | ||||
subtask3 | 0/7 | ||||||
13 | Wrong answer | 3ms | 3224 KiB | ||||
14 | Accepted | 4ms | 3584 KiB | ||||
15 | Accepted | 6ms | 3732 KiB | ||||
16 | Wrong answer | 6ms | 3704 KiB | ||||
17 | Wrong answer | 7ms | 4004 KiB | ||||
18 | Accepted | 6ms | 4000 KiB | ||||
19 | Accepted | 7ms | 4220 KiB | ||||
20 | Accepted | 7ms | 4420 KiB | ||||
21 | Wrong answer | 8ms | 4572 KiB | ||||
subtask4 | 0/11 | ||||||
22 | Wrong answer | 92ms | 9776 KiB | ||||
23 | Wrong answer | 90ms | 9860 KiB | ||||
24 | Accepted | 93ms | 9968 KiB | ||||
25 | Wrong answer | 93ms | 10196 KiB | ||||
26 | Accepted | 98ms | 10280 KiB | ||||
27 | Accepted | 104ms | 10172 KiB | ||||
subtask5 | 0/22 | ||||||
28 | Wrong answer | 7ms | 4888 KiB | ||||
29 | Wrong answer | 7ms | 4860 KiB | ||||
30 | Wrong answer | 7ms | 4864 KiB | ||||
31 | Wrong answer | 7ms | 4864 KiB | ||||
32 | Wrong answer | 7ms | 4864 KiB | ||||
33 | Wrong answer | 8ms | 4872 KiB | ||||
34 | Wrong answer | 6ms | 4904 KiB | ||||
subtask6 | 0/51 | ||||||
35 | Wrong answer | 103ms | 10212 KiB | ||||
36 | Wrong answer | 101ms | 10312 KiB | ||||
37 | Wrong answer | 104ms | 10288 KiB | ||||
38 | Wrong answer | 105ms | 10176 KiB | ||||
39 | Wrong answer | 107ms | 10196 KiB | ||||
40 | Wrong answer | 114ms | 10200 KiB | ||||
41 | Wrong answer | 85ms | 10284 KiB | ||||
42 | Wrong answer | 97ms | 10308 KiB | ||||
43 | Accepted | 104ms | 10176 KiB | ||||
44 | Wrong answer | 97ms | 10180 KiB | ||||
45 | Wrong answer | 97ms | 10292 KiB |