This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
/*
The sparkler should move in both directions from the initial person after it is lit
If two people meet, they should do so as soon as possible, otherwise it wouldn't make a difference
A path actually depends on the sum of distances of the first and last people from the person with the sparkler
*/
int main(){
std::ios::sync_with_stdio(0);
std::cin.tie(0);
long long n,k,t;
std::cin>>n>>k>>t;
k--;
std::vector<int> places;
for(int i=0;i<n;i++){
int a;
std::cin>>a;
places.push_back(a);
}
long long lower=-1,upper=1e9;//min distance a sparkler can burn for
while(lower+1<upper){
long long mid=(lower+upper)/2;
//std::cout<<mid<<'\n';
std::vector<std::pair<long long,long long>> toleft,toright;//cost, profit
long long curmin=0;
long long cursum=0;
for(int i=k-1;i>=0;i--){
//std::cout<<i+1<<"?"<<i<<'\n';
cursum-=(places[i+1]-places[i]);
curmin=std::min(cursum,curmin);
cursum+=mid;
if(cursum>0){
toleft.push_back({-curmin,cursum});
cursum=0;curmin=0;
}
}
std::pair<long long,long long> leftex={-curmin,-cursum};//cursum <= 0
//std::cout<<"yes\n";
curmin=0;cursum=0;
for(int i=k;i<n-1;i++){
//std::cout<<i+1<<"?"<<i<<'\n';
cursum-=(places[i+1]-places[i]);
curmin=std::min(cursum,curmin);
cursum+=mid;
if(cursum>0){
toright.push_back({-curmin,cursum});
cursum=0;curmin=0;
}
}
std::pair<long long,long long> rightex={-curmin,-cursum};
//std::cout<<leftex.first<<' '<<leftex.second<<'\n';
long long lp=0,rp=0,cur=mid;
while(lp<toleft.size()||rp<toright.size()){
//std::cout<<lp<<' '<<rp<<"lprp\n";
if(lp<toleft.size()&&cur>=toleft[lp].first){
cur+=toleft[lp].second;
lp++;
}else if(rp<toright.size()&&cur>=toright[rp].first){
cur+=toright[rp].second;
rp++;
}else{
cur=-1;
break;
}
}
if(cur>=std::min(std::max(leftex.first,leftex.second+rightex.first),std::max(leftex.first+rightex.second,rightex.first))){
upper=mid;
}else{
lower=mid;
}
}
//upper/=2;//towards each other
std::cout<<(upper+2*t-1)/(2*t)<<'\n';
}
Compilation message (stderr)
sparklers.cpp: In function 'int main()':
sparklers.cpp:56:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(lp<toleft.size()||rp<toright.size()){
| ~~^~~~~~~~~~~~~~
sparklers.cpp:56:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(lp<toleft.size()||rp<toright.size()){
| ~~^~~~~~~~~~~~~~~
sparklers.cpp:58:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(lp<toleft.size()&&cur>=toleft[lp].first){
| ~~^~~~~~~~~~~~~~
sparklers.cpp:61:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | }else if(rp<toright.size()&&cur>=toright[rp].first){
| ~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |