#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e9+7;
const int LIM=1e3+7;
ll T[LIM], n, k, t;
ll odw[LIM][LIM], dp[LIM][LIM];
ll solve(ll l, ll r, ll x) {
if(odw[l][r]) return dp[l][r];
odw[l][r]=1;
dp[l][r]=-INF;
if(l>r || r<k || k<l) return dp[l][r];
ll a=solve(l+1, r, x), b=solve(l, r-1, x);
if(a>=T[l+1]-T[l]) dp[l][r]=max(dp[l][r], a-T[l+1]+T[l]+t*x*2);
if(b>=T[r]-T[r-1]) dp[l][r]=max(dp[l][r], b-T[r]+T[r-1]+t*x*2);
return dp[l][r];
}
bool check(ll x) {
rep(i, n) rep(j, n) odw[i][j]=dp[i][j]=0;
dp[k][k]=2*x*t;
odw[k][k]=1;
return solve(0, n-1, x)>=0;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k >> t; --k;
rep(i, n) cin >> T[i];
ll po=0, ko=INF;
while(po<ko) {
ll sr=(po+ko)/2;
if(check(sr)) ko=sr; else po=sr+1;
}
cout << po << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
46 ms |
15052 KB |
Output is correct |
23 |
Correct |
27 ms |
12892 KB |
Output is correct |
24 |
Correct |
18 ms |
14940 KB |
Output is correct |
25 |
Correct |
18 ms |
16372 KB |
Output is correct |
26 |
Correct |
47 ms |
16292 KB |
Output is correct |
27 |
Correct |
56 ms |
16300 KB |
Output is correct |
28 |
Correct |
81 ms |
16220 KB |
Output is correct |
29 |
Correct |
74 ms |
16216 KB |
Output is correct |
30 |
Correct |
56 ms |
16216 KB |
Output is correct |
31 |
Correct |
62 ms |
16216 KB |
Output is correct |
32 |
Correct |
89 ms |
16352 KB |
Output is correct |
33 |
Correct |
83 ms |
16352 KB |
Output is correct |
34 |
Correct |
46 ms |
16352 KB |
Output is correct |
35 |
Correct |
70 ms |
16220 KB |
Output is correct |
36 |
Correct |
34 ms |
16372 KB |
Output is correct |
37 |
Correct |
34 ms |
16220 KB |
Output is correct |
38 |
Correct |
73 ms |
16220 KB |
Output is correct |
39 |
Correct |
25 ms |
16220 KB |
Output is correct |
40 |
Correct |
89 ms |
16340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
46 ms |
15052 KB |
Output is correct |
23 |
Correct |
27 ms |
12892 KB |
Output is correct |
24 |
Correct |
18 ms |
14940 KB |
Output is correct |
25 |
Correct |
18 ms |
16372 KB |
Output is correct |
26 |
Correct |
47 ms |
16292 KB |
Output is correct |
27 |
Correct |
56 ms |
16300 KB |
Output is correct |
28 |
Correct |
81 ms |
16220 KB |
Output is correct |
29 |
Correct |
74 ms |
16216 KB |
Output is correct |
30 |
Correct |
56 ms |
16216 KB |
Output is correct |
31 |
Correct |
62 ms |
16216 KB |
Output is correct |
32 |
Correct |
89 ms |
16352 KB |
Output is correct |
33 |
Correct |
83 ms |
16352 KB |
Output is correct |
34 |
Correct |
46 ms |
16352 KB |
Output is correct |
35 |
Correct |
70 ms |
16220 KB |
Output is correct |
36 |
Correct |
34 ms |
16372 KB |
Output is correct |
37 |
Correct |
34 ms |
16220 KB |
Output is correct |
38 |
Correct |
73 ms |
16220 KB |
Output is correct |
39 |
Correct |
25 ms |
16220 KB |
Output is correct |
40 |
Correct |
89 ms |
16340 KB |
Output is correct |
41 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |