#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(;;) {
if(i == pl) break;
if(g(i-1) <= g(r)) i--;
if(g(i) <= g(l)) break;
}
if(i != l && g(i) <= g(l)) {
flag = true;
l = i;
}
for(i = r;;) {
if(i == pr) break;
if(g(l) <= g(i+1)) i++;
if(g(r) <= g(i)) break;
}
if(i != r && g(r) <= g(i)) {
flag = true;
r = i;
}
if(!flag) break;
}
if(pl != l || pr != r) return false;
for(l = 1, r = N;;) {
bool flag = false;
int i = l;
for(;;) {
if(i == pl) break;
if(g(i+1) <= g(r)) i++;
if(g(i) <= g(l)) break;
}
if(i != l && g(i) <= g(l)) {
flag = true;
l = i;
}
for(i = r;;) {
if(i == pr) break;
if(g(l) <= g(i-1)) i--;
if(g(r) <= g(i)) 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Execution timed out |
2058 ms |
492 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Execution timed out |
2058 ms |
492 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Execution timed out |
2058 ms |
492 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |