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;
typedef long long ll;
const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;
#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define sz(x) ((int)(x).size())
#define mp make_pair
#define pb push_back
bool mini(auto &x, const auto &y) {
if (y < x) {
x = y;
return 1;
}
return 0;
}
bool maxi(auto &x, const auto &y) {
if (y > x) {
x = y;
return 1;
}
return 0;
}
void run();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
run();
return 0;
}
const int N = 5005;
int n, k;
ll t;
ll x[N], a[N];
bool dp[N][N];
bool check(ll s) {
memset(dp, 0, sizeof dp);
dp[k][k] = 1;
rep(i, 0, n) {
a[i] = x[i] - 2 * s * t * i;
}
rep(len, 2, n + 1) {
rep(l, 0, n) {
int r = l + len - 1;
if (r >= n) {
break;
}
dp[l][r] = ((dp[l + 1][r] || dp[l][r - 1]) && a[l] >= a[r]);
}
}
return dp[0][n - 1];
}
void run() {
cin >> n >> k >> t;
k--;
rep(i, 0, n) {
cin >> x[i];
}
ll left = -1;
ll right = (x[n - 1] + t) / t;
while (right - left > 1) {
ll mid = (left + right) / 2;
if (check(mid)) {
right = mid;
} else {
left = mid;
}
}
cout << right << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |