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>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
const int MAXN = 100005;
int A[MAXN];
int N, K, T, P;
ll f(int P, int i) { return ll(A[i]) - 2ll * P * T * i; }
ll g(int P, int i) { return -f(P, i); }
ll g(int i) { return g(P, i); }
bool isp(int P) {
::P = P;
if(g(1) > g(N)) return false;
int pl = K, pr = K, l = K, r = K;
for(int i = 1; i <= K; i++) if(g(i) < g(pl)) pl = i;
for(int i = K; i <= N; i++) if(g(pr) <= g(i)) pr = i;
for(;;) {
bool flag = false;
int i = l;
for(; pl < i;) {
if(g(i-1) <= g(r)) {
i--;
if(g(i) <= g(l)) break;
continue;
}
break;
}
if(i < l && g(i) <= g(l)) {
flag = true;
l = i;
}
for(i = r; i < pr;) {
if(g(l) <= g(i+1)) {
i++;
if(g(r) <= g(i)) break;
continue;
}
break;
}
if(r < i && g(r) <= g(i)) {
flag = true;
r = i;
}
if(!flag) break;
}
if(l != pl || r != pr) return false;
l = 1; r = N;
for(;;) {
bool flag = false;
int i = l;
for(; i < pl;) {
if(g(i+1) <= g(r)) {
i++;
if(g(i) <= g(l)) break;
continue;
}
break;
}
if(l < i && g(i) <= g(l)) {
flag = true;
l = i;
}
for(i = r; pr < i;) {
if(g(l) <= g(i-1)) {
i--;
if(g(r) <= g(i)) break;
continue;
}
break;
}
if(i < r && g(r) <= g(i)) {
flag = true;
r = i;
}
if(!flag) break;
}
return l == pl && r == pr;
}
int getAns() {
int s = 0, e = INF/T+2; for(int m; s < e;) {
m = (s+e) >> 1;
if(isp(m)) e = m;
else s = m+1;
}
return s;
}
int main() {
ios::sync_with_stdio(false);
cin >> N >> K >> T;
for(int i = 1; i <= N; i++) cin >> A[i];
cout << getAns() << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |