This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//InTheNameOfGOD
//PRS;)
#pragma GCC optimize("no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i < r; ++i)
#define per(i, l, r) for(int i = r - 1; i >= l; --i)
#define Fast cin.tie(0) -> sync_with_stdio(0);
#define X first
#define Y second
typedef long double ld;
typedef long long ll;
using namespace std;
typedef pair<int, int> pi;
constexpr int inf = 1e9;
vector<int> a;
int cnt, k, md, n;
inline bool ig(vector<ld> x, vector<ld> y)
{
pi pl = {0, 0}, pr = {0, 0};
int s1 = x.size() - 1, s2 = y.size() - 1;
bool f = 1;
while(f)
{
f = 0;
while(pl.Y < s1 && x[pl.Y + 1] <= y[pr.X])
{
f = 1;
if(x[++pl.Y] < x[pl.X]) pl.X = pl.Y;
}
while(pr.Y < s2 && x[pl.X] <= y[pr.Y + 1])
{
f = 1;
if(y[++pr.Y] > y[pr.X]) pr.X = pr.Y;
}
}
return pl.Y == s1 && pr.Y == s2;
}
inline bool doj()
{
vector<ld> x, y;
per(i, 0, k + 1) x.push_back((ld)2 * md * cnt * i - a[i]);
rep(i, k, n) y.push_back((ld)2 * md * cnt * i - a[i]);
if(!ig(x, y)) return 0;
reverse(x.begin(), x.end()), reverse(y.begin(), y.end());
if(!ig(x, y)) return 0;
return 1;
}
int main()
{
Fast
cin >> n >> k >> cnt;
a.resize(n), k--;
rep(i, 0, n) cin >> a[i];
int l = 0, r = inf;
while(l < r)
{
md = l + r >> 1;
if(doj()) r = md;
else l = md + 1;
}
cout << l << '\n';
}
Compilation message (stderr)
sparklers.cpp: In function 'int main()':
sparklers.cpp:58:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | md = l + r >> 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... |