#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
#define int long long
#define ld long double
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 6e5 + 10 , sq = 3 , maxq = 1e7 + 1 , inf = 1e18 + 10 , mod= 998244353 ,lg = 20 ;
int n ,t , k;
vector <ld> a , b ;
int x[maxn] ;
ld pa[maxn] , pb[maxn] , ma[maxn] , mb[maxn] ;
int sl(){
ld sm = 0 , sm2 , val =0 ;int l = 1 ;
for(int i =1 ; i < a.size() ; i++){
sm += a[i];
if(sm >= 0){
val += sm ;
sm = 0 ;
l = i+1 ;
}
}
sm2 = sm ;
sm = 0 ;int l2 = 1 ;
for(int i = 1 ;i < b.size() ; i++){
sm += b[i] ;
if(sm >= 0){
val += sm ;
sm =0 ;
l2 = i+1 ;
}
}
ld val2 = val;
bool ok1 = 1 , ok2 = 1;
for(int i = l ; i < a.size() ; i++){
val2 += a[i] ;
if(val2 < 0)ok1 = 0 ;
}
for(int i = l2 ; i < b.size() ; i++){
val2 += b[i] ;
if(val2 < 0)ok1 =0 ;
}
for(int i = l2 ; i < b.size() ; i++){
val += b[i] ;
if(val < 0)ok2 =0 ;
}
for(int i = l ; i < a.size() ; i++){
val += a[i] ;
if(val < 0)ok2 =0 ;
}
return ok1|ok2 ;
}
bool ch(int z){
a.clear();b.clear();
a.pb(0);
b.pb(0) ;
a.pb((ld)t);
for(int i = k+1; i <= n ; i++){
a.pb(-(ld)(x[i] - x[i-1])/(ld)(2*(ld)z));
a.pb((ld)t) ;
}
for(int i = k-1 ; i >= 1; i--){
b.pb(-(ld)(x[i+1] - x[i])/(ld)(2*(ld)z));
b.pb((ld)t) ;
}
return sl() ;
}
signed main() {
ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
cin >> n >> k >> t ;
for(int i = 1; i <= n ; i++){
cin >> x[i] ;
}
int l = 0 , r = 1e9 ;
while(r-l>1){
int mid = (l+r)/2 ;
if(ch(mid) == 1)r= mid ;
else l = mid ;
}
cout << r << "\n";
}
/*
*/
Compilation message
sparklers.cpp: In function 'long long int sl()':
sparklers.cpp:21:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i =1 ; i < a.size() ; i++){
| ~~^~~~~~~~~~
sparklers.cpp:31:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 1 ;i < b.size() ; i++){
| ~~^~~~~~~~~~
sparklers.cpp:41:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = l ; i < a.size() ; i++){
| ~~^~~~~~~~~~
sparklers.cpp:45:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = l2 ; i < b.size() ; i++){
| ~~^~~~~~~~~~
sparklers.cpp:49:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i = l2 ; i < b.size() ; i++){
| ~~^~~~~~~~~~
sparklers.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = l ; i < a.size() ; i++){
| ~~^~~~~~~~~~
sparklers.cpp:20:15: warning: variable 'sm2' set but not used [-Wunused-but-set-variable]
20 | ld sm = 0 , sm2 , val =0 ;int l = 1 ;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2516 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2516 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2516 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |