#include <stdio.h>
#define N 1000
#define INF 0x3f3f3f3f
long long min(long long a, long long b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int solve(int *xx, int n, int i, int b) {
static int dp[N][N];
int l, r;
for (l = i; l >= 0; l--)
for (r = i; r < n; r++) {
dp[l][r] = -1;
if (l == i && r == i)
dp[l][r] = b;
else {
if (l < i && dp[l + 1][r] >= xx[l + 1] - xx[l])
dp[l][r] = max(dp[l][r], min(dp[l + 1][r] - (xx[l + 1] - xx[l]) + b, INF));
if (r > i && dp[l][r - 1] >= xx[r] - xx[r - 1])
dp[l][r] = max(dp[l][r], min(dp[l][r - 1] - (xx[r] - xx[r - 1]) + b, INF));
}
}
return dp[0][n - 1] >= 0;
}
int main() {
static int xx[N];
int n, i_, t, i, lower, upper;
scanf("%d%d%d", &n, &i_, &t), i_--;
for (i = 0; i < n; i++)
scanf("%d", &xx[i]);
lower = -1, upper = INF;
while (upper - lower > 1) {
int s = (lower + upper) / 2;
if (solve(xx, n, i_, min((long long) t * s * 2, INF)))
upper = s;
else
lower = s;
}
printf("%d\n", upper);
return 0;
}
Compilation message
sparklers.c: In function 'main':
sparklers.c:32:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | scanf("%d%d%d", &n, &i_, &t), i_--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.c:34:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d", &xx[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
0 ms |
292 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
0 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
0 ms |
292 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
0 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
16 ms |
1236 KB |
Output is correct |
23 |
Correct |
9 ms |
980 KB |
Output is correct |
24 |
Correct |
5 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
304 KB |
Output is correct |
26 |
Correct |
15 ms |
832 KB |
Output is correct |
27 |
Correct |
18 ms |
964 KB |
Output is correct |
28 |
Correct |
34 ms |
2516 KB |
Output is correct |
29 |
Correct |
28 ms |
2840 KB |
Output is correct |
30 |
Correct |
21 ms |
3412 KB |
Output is correct |
31 |
Correct |
21 ms |
3244 KB |
Output is correct |
32 |
Correct |
27 ms |
2004 KB |
Output is correct |
33 |
Correct |
29 ms |
2004 KB |
Output is correct |
34 |
Correct |
15 ms |
3540 KB |
Output is correct |
35 |
Correct |
36 ms |
2900 KB |
Output is correct |
36 |
Correct |
9 ms |
596 KB |
Output is correct |
37 |
Correct |
10 ms |
620 KB |
Output is correct |
38 |
Correct |
26 ms |
2900 KB |
Output is correct |
39 |
Correct |
8 ms |
3892 KB |
Output is correct |
40 |
Correct |
35 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
296 KB |
Output is correct |
10 |
Correct |
0 ms |
292 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
0 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
16 ms |
1236 KB |
Output is correct |
23 |
Correct |
9 ms |
980 KB |
Output is correct |
24 |
Correct |
5 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
304 KB |
Output is correct |
26 |
Correct |
15 ms |
832 KB |
Output is correct |
27 |
Correct |
18 ms |
964 KB |
Output is correct |
28 |
Correct |
34 ms |
2516 KB |
Output is correct |
29 |
Correct |
28 ms |
2840 KB |
Output is correct |
30 |
Correct |
21 ms |
3412 KB |
Output is correct |
31 |
Correct |
21 ms |
3244 KB |
Output is correct |
32 |
Correct |
27 ms |
2004 KB |
Output is correct |
33 |
Correct |
29 ms |
2004 KB |
Output is correct |
34 |
Correct |
15 ms |
3540 KB |
Output is correct |
35 |
Correct |
36 ms |
2900 KB |
Output is correct |
36 |
Correct |
9 ms |
596 KB |
Output is correct |
37 |
Correct |
10 ms |
620 KB |
Output is correct |
38 |
Correct |
26 ms |
2900 KB |
Output is correct |
39 |
Correct |
8 ms |
3892 KB |
Output is correct |
40 |
Correct |
35 ms |
1620 KB |
Output is correct |
41 |
Runtime error |
9 ms |
1492 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |