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>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
vector <pll> L, R;
ll X[101010], D[101010];
ll n, k, t;
bool check(ll v)
{
ll i, j, l, r, f, l1, l2, r1, r2;
for(i=1; i<=n; i++){
D[i] = 2 * v * t * i - X[i];
}
if(D[1] > D[n]) return 0;
for(l=k, r=k, i=k-1, j=k+1, f=0; ; f=0){
for(; i >= 1 && D[i] > D[l] && D[i] <= D[r]; i--);
for(; j <= n && D[j] < D[r] && D[j] >= D[l]; j++);
if(i >= 1 && D[i] <= D[l]) l = i --, f = 1;
if(j <= n && D[j] >= D[r]) r = j ++, f = 1;
if(!f) break;
}
l1 = l; r1 = r;
for(l=1, r=n, i=2, j=n-1, f=0; ; f=0){
for(; i <= k && D[i] > D[l] && D[i] <= D[r]; i++);
for(; j >= k && D[j] < D[r] && D[j] >= D[l]; j--);
if(i <= k && D[i] <= D[l]) l = i ++, f = 1;
if(j >= k && D[j] >= D[r]) r = j --, f = 1;
if(!f) break;
}
l2 = l; r2 = r;
return (l1 <= l2) && (r2 <= r1);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
ll i, s, e;
cin >> n >> k >> t;
for(i=1; i<=n; i++){
cin >> X[i];
}
for(s=0, e=1e12/t; s<=e; ){
if(check(s + e >> 1)) e = (s + e >> 1) - 1;
else s = (s + e >> 1) + 1;
}
cout << e + 1 << "\n";
return 0;
}
Compilation message (stderr)
sparklers.cpp: In function 'int main()':
sparklers.cpp:61:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(check(s + e >> 1)) e = (s + e >> 1) - 1;
~~^~~
sparklers.cpp:61:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(check(s + e >> 1)) e = (s + e >> 1) - 1;
~~^~~
sparklers.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else s = (s + e >> 1) + 1;
~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |