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) {
vector<vector<bool>> dp(n, vector<bool>(n));
vector<vector<bool>> was(n, vector<bool>(n));
function<bool(int, int)> Solve = [&](int L, int R) {
if (was[L][R]) {
return dp[L][R];
}
was[L][R] = true;
if (L == R) {
if (L == k) {
dp[L][R] = true;
} else {
dp[L][R] = false;
}
return dp[L][R];
}
long long f = t * 1LL * (R - L);
if (f <= 5e8) {
f *= 2;
}
if (f <= 1e9) {
f *= s;
}
if ((x[R] - x[L]) <= f) {
if (Solve(L + 1, R) || Solve(L, R - 1)) {
dp[L][R] = true;
}
}
return dp[L][R];
};
return Solve(0, n - 1);
};
long long low = 0, high = 2e9, ans = 0;
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:49:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | 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... |