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>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 1010;
const ll inf = 1ll << 55;
int n, k, T;
int pos[MAX_N];
bool dp[MAX_N][MAX_N];
ll a[MAX_N];
bool valid(ll S) {
memset(dp, 0, sizeof(dp));
dp[k][k] = true;
for (int l = k;l >= 1;--l)
for (int r = k;r <= n;++r) {
auto valid = [&](ll d) {
return 2 * S * (r-l+1) * T - (pos[r] - pos[l]) >= d;
};
if (dp[l][r]) {
if (r < n) {
ll d = pos[r+1] - pos[r];
if (valid(d))
dp[l][r+1] = true;
}
if (l > 1) {
ll d = pos[l] - pos[l-1];
if (valid(d))
dp[l-1][r] = true;
}
}
}
return dp[1][n];
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> k >> T;
for (int i = 1;i <= n;++i)
cin >> pos[i];
if (n <= 1) return puts("0"), 0;
assert(n < MAX_N);
ll L = 1, R = 2 * pos[n], M;
while (L < R) {
M = L + R >> 1;
if (valid(M))
R = M;
else L = M + 1;
}
cout << L << '\n';
}
Compilation message (stderr)
sparklers.cpp: In function 'int32_t main()':
sparklers.cpp:73:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | M = L + R >> 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... |