# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
998024 | lovrot | Sparklers (JOI17_sparklers) | C++17 | 1 ms | 348 KiB |
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 <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int OO = 1e9 + 10;
int n, t, k, A[N];
ll B[N];
bool solve(int l, int r, int lo, int hi) { // lo <= l | r <= hi
int l_ = l, r_ = r;
for(; lo >= 0 && B[lo] >= B[r]; --lo) {
if(B[lo] > B[l_]) {
l_ = lo;
}
}
for(; hi < n && B[hi] <= B[l]; ++hi) {
if(B[hi] < B[r_]) {
r_ = hi;
}
}
if(lo < 0 && hi >= n) { return 1; }
if(l == l_ && r == r_) { return 0; }
return solve(l_, r_, lo, hi);
}
int main() {
scanf("%d%d%d", &n, &k, &t);
for(int i = 0; i < n; ++i) { scanf("%d", A + i); }
int lo = -1, hi = OO / t + 1;
for(int mi = (lo + hi) / 2; hi - lo > 1; mi = (lo + hi) / 2) {
for(int i = 0; i < n; ++i) {
B[i] = A[i] - (ll) 2 * mi * t * i;
}
if(solve(k - 1, k - 1, k - 1, k - 1)) { hi = mi; }
else { lo = mi; }
}
printf("%d\n", hi);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |