105582024-04-05 13:20:01111Az IKPC legerősebb csapatacpp17Wrong answer 0/100111ms9892 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{};
			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(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+c*h<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Wrong answer3ms2164 KiB
subtask20/9
3Accepted3ms2300 KiB
4Wrong answer3ms2488 KiB
5Wrong answer3ms2584 KiB
6Accepted3ms2772 KiB
7Accepted3ms2796 KiB
8Wrong answer3ms2796 KiB
9Wrong answer3ms2796 KiB
10Accepted3ms2772 KiB
11Wrong answer3ms3008 KiB
12Wrong answer3ms2980 KiB
subtask30/7
13Wrong answer3ms3368 KiB
14Wrong answer4ms3528 KiB
15Wrong answer6ms3868 KiB
16Wrong answer6ms4172 KiB
17Wrong answer6ms4348 KiB
18Accepted6ms4208 KiB
19Wrong answer6ms4220 KiB
20Wrong answer7ms4264 KiB
21Accepted8ms4548 KiB
subtask40/11
22Wrong answer90ms9748 KiB
23Wrong answer89ms9740 KiB
24Accepted89ms9848 KiB
25Accepted89ms9852 KiB
26Wrong answer97ms9740 KiB
27Accepted96ms9852 KiB
subtask50/22
28Wrong answer7ms4428 KiB
29Wrong answer7ms4432 KiB
30Accepted7ms4436 KiB
31Wrong answer7ms4428 KiB
32Accepted7ms4624 KiB
33Wrong answer8ms4428 KiB
34Wrong answer6ms4432 KiB
subtask60/51
35Wrong answer103ms9788 KiB
36Wrong answer101ms9788 KiB
37Wrong answer104ms9804 KiB
38Accepted105ms9788 KiB
39Accepted104ms9892 KiB
40Accepted111ms9892 KiB
41Wrong answer82ms9744 KiB
42Accepted90ms9848 KiB
43Accepted96ms9848 KiB
44Accepted90ms9740 KiB
45Accepted90ms9756 KiB