#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::vector<std::pair<long long,long long>> toleft,toright;//cost, profit
long long curmin=0;
long long cursum=0;
for(int i=k;i--;){
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};
//std::cout<<"yes\n";
curmin=0;cursum=0;
for(int i=k;i<n-1;i++){
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};
long long lp=0,rp=0,cur=mid;
while(lp<toleft.size()||rp<toright.size()){
//std::cout<<"this\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
sparklers.cpp: In function 'int main()':
sparklers.cpp:53: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]
53 | while(lp<toleft.size()||rp<toright.size()){
| ~~^~~~~~~~~~~~~~
sparklers.cpp:53: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]
53 | while(lp<toleft.size()||rp<toright.size()){
| ~~^~~~~~~~~~~~~~~
sparklers.cpp:55: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]
55 | if(lp<toleft.size()&&cur>=toleft[lp].first){
| ~~^~~~~~~~~~~~~~
sparklers.cpp:58: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]
58 | }else if(rp<toright.size()&&cur>=toright[rp].first){
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |