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>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, t;
cin >> n >> k >> t;
--k;
vector<int> x(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
}
auto Check = [&](long long s) {
if (2 * s * t >= (long long) 1e9) {
return true;
}
vector<long long> L;
vector<long long> R;
for (int i = k; i >= 0; i--) {
L.push_back(x[i] - 2 * s * t * i);
}
for (int i = k; i < n; i++) {
R.push_back(x[i] - 2 * s * t * i);
}
int i = 0, j = 0;
long long mx = L[0];
long long mn = R[0];
while (i < (int) L.size() || j < (int) R.size()) {
if (i < (int) L.size() && L[i] >= mn) {
mx = max(mx, L[i]);
i += 1;
continue;
}
if (j < (int) R.size() && R[j] <= mx) {
mn = min(mn, R[j]);
j += 1;
continue;
}
break;
}
if (i != (int) L.size() || j != (int) R.size()) {
return false;
} else {
return true;
}
};
long long low = 0, high = 1e9, ans = -1;
while (low <= high) {
long long mid = low + high >> 1;
if (Check(mid)) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
sparklers.cpp: In function 'int main()':
sparklers.cpp:51:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
51 | long long mid = low + high >> 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... |