#include <bits/stdc++.h>
using namespace std;
int n,k;double t;
double arr[100001];
bool check(double mid){
int l = k-1 , r = k+1 , lin = k , rin = k;
double te = t , tel = t , ter = t , suml = 0, sumr = 0;
double minl = 1000000000.0;
double minr = 1000000000.0;
while(1){
double mi = 0;
bool ss = 0;
while(l>=0){
double dis = (arr[l+1]-arr[l])/2;
double tim = dis/mid;
if(tel<tim){
break;
}
minl = min(minl,tel-tim);
tel-=tim;tel+=t;
suml+=t-tim;
if(suml>0){
ss = 1;
lin = l;
minr+=suml;
te = tel;
ter += suml;
suml = 0;
minl = 1000000000.0;
}
l--;
}while(r<n){
double dis = (arr[r]-arr[r-1])/2;
double tim = dis/mid;
if(ter<tim){
break;
}
minr = min(minr,ter-tim);
ter-=tim;
ter+=t;
sumr+=t-tim;
if(sumr>0){
ss = 1;
rin = r;
minl+=sumr;
te = ter;
tel += sumr;
sumr = 0;
minr = 1000000000.0;
}
r++;
}
if(lin==0&&rin==n-1)return 1;
if(l==-1&&r==n&&((minr>=te-suml)||(minl>=te-sumr))){
return 1;
}
if(ss==0)return 0;
}
return 1;
}
int main(){
cin>>n>>k>>t;
k--;
for(int i = 0;i<n;i++)cin>>arr[i];
sort(arr,arr+n);
int l = 0 , r = 1e9 , ans = 0;
while(l<=r){
int mid = (l+r)/2;
if(check(mid)){
r = mid-1;
ans = mid;
}else l = mid+1;
}
cout<<ans;
}
Compilation message
sparklers.cpp: In function 'bool check(double)':
sparklers.cpp:13:16: warning: unused variable 'mi' [-Wunused-variable]
13 | double mi = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |