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>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
#define pb push_back
#define nl '\n'
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i, x, y) for(int i = x;i<=y;i++)
#define forn(i, y, x) for(int i = y; i >= x; i--)
const int N = 1e5 + 10;
int n , k , t;
int x[N];
bool check(vector<int> a , vector<int> b)
{
int mx = a[0] , mn = b[0];
int i = 1 , j = 1;
while(true)
{
if(i < (int)a.size() && a[i] >= mn)
mx = max(mx , a[i++]);
else if(j < (int)b.size() && b[j] <= mx)
mn = min(mn , b[j++]);
else
break;
}
return (i == (int)a.size() && j == (int)b.size());
}
bool check(int s)
{
vector<int> a , b;
forn(i , k , 1)
a.pb(x[i] - 2*t*s * i);
forr(i , k , n)
b.pb(x[i] - 2*t*s * i);
if(!check(a , b))
return 0;
reverse(a.begin() , a.end());
reverse(b.begin() , b.end());
return check(a , b);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>t;
bool acc = 1;
forr(i , 1 , n) {
cin >> x[i];
if (x[i] != 0)
acc = 0;
}
if(acc)
{
cout<<0<<nl;
return 0;
}
int lo = 0 , hi = 1e10;
while(lo + 1 < hi)
{
int mid = (lo + hi)/2;
if(check(mid))
hi = mid;
else
lo = mid;
}
cout<<hi<<nl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |