#include <stdio.h>
#define N 100000
#define INF 0x3f3f3f3f
long long min(long long a, long long b) { return a < b ? a : b; }
int solve(int *xx, int n, int i, int t, int s) {
int l, r;
long long x;
l = r = i, x = min((long long) t * s * 2, INF);
while (l > 0 || r + 1 < n)
if (r + 1 == n || l > 0 && xx[l] - xx[l - 1] < xx[r + 1] - xx[r]) {
x -= xx[l] - xx[l - 1];
if (x < 0)
return 0;
l--, x = min(x + (long long) t * s * 2, INF);
} else {
x -= xx[r + 1] - xx[r];
if (x < 0)
return 0;
r++, x = min(x + (long long) t * s * 2, INF);
}
return 1;
}
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_, t, s))
upper = s;
else
lower = s;
}
printf("%d\n", upper);
return 0;
}
Compilation message
sparklers.c: In function 'solve':
sparklers.c:14:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
14 | if (r + 1 == n || l > 0 && xx[l] - xx[l - 1] < xx[r + 1] - xx[r]) {
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |