#include <stdio.h>
#define N 100000
#define INF 0x3f3f3f3f
int solve(int *xx, int n, int i, int t, int s) {
int l, r;
long long x;
l = r = i, x = (long long) t * s * 2;
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 += (long long) t * s * 2;
} else {
x -= xx[r + 1] - xx[r];
if (x < 0)
return 0;
r++, x += (long long) t * s * 2;
}
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:12:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
12 | if (r + 1 == n || l > 0 && xx[l] - xx[l - 1] < xx[r + 1] - xx[r]) {
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.c: In function 'main':
sparklers.c:30:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d%d%d", &n, &i_, &t), i_--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.c:32:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | scanf("%d", &xx[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |