#include <stdio.h>
#define N 1000000
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
int solve(int *aa, int *bb, int n, long long k_) {
int i;
long long k, c;
k = k_;
for (i = n - 1; i > 0; i--) {
if (aa[i] - k * 2 > bb[i])
return -1;
k = min(bb[i] - (aa[i] - k * 2), INF);
}
c = bb[0] - (aa[0] + k_ - k * 2);
return c == 0 ? 0 : (c < 0 ? -1 : 1);
}
int main() {
static int aa[N], bb[N];
int n, i, same, zero;
long long lower, upper;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &aa[i], &bb[i]);
same = 1;
for (i = 0; i < n; i++)
if (aa[i] != bb[i]) {
same = 0;
break;
}
if (same) {
printf("Yes\n");
return 0;
}
zero = 1;
for (i = 0; i < n; i++)
if (bb[i] != 0) {
zero = 0;
break;
}
if (zero) {
printf("No\n");
return 0;
}
lower = 0, upper = INF;
while (upper - lower > 1) {
long long k = (lower + upper) / 2;
if (solve(aa, bb, n, k) <= 0)
lower = k;
else
upper = k;
}
printf(solve(aa, bb, n, lower) == 0 ? "Yes\n" : "No\n");
return 0;
}
Compilation message
remittance.c: In function 'main':
remittance.c:27:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
remittance.c:29:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d", &aa[i], &bb[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 |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
220 KB |
Output is correct |
9 |
Correct |
0 ms |
220 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
224 KB |
Output is correct |
13 |
Correct |
0 ms |
224 KB |
Output is correct |
14 |
Correct |
0 ms |
220 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
220 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
220 KB |
Output is correct |
9 |
Correct |
0 ms |
220 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
224 KB |
Output is correct |
13 |
Correct |
0 ms |
224 KB |
Output is correct |
14 |
Correct |
0 ms |
220 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
220 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
284 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
220 KB |
Output is correct |
38 |
Correct |
0 ms |
216 KB |
Output is correct |
39 |
Correct |
1 ms |
220 KB |
Output is correct |
40 |
Correct |
1 ms |
220 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
288 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
288 KB |
Output is correct |
46 |
Correct |
1 ms |
292 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
292 KB |
Output is correct |
52 |
Correct |
0 ms |
292 KB |
Output is correct |
53 |
Correct |
0 ms |
292 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
288 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
288 KB |
Output is correct |
60 |
Correct |
0 ms |
292 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
220 KB |
Output is correct |
9 |
Correct |
0 ms |
220 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
224 KB |
Output is correct |
13 |
Correct |
0 ms |
224 KB |
Output is correct |
14 |
Correct |
0 ms |
220 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
220 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
284 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
220 KB |
Output is correct |
38 |
Correct |
0 ms |
216 KB |
Output is correct |
39 |
Correct |
1 ms |
220 KB |
Output is correct |
40 |
Correct |
1 ms |
220 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
288 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
288 KB |
Output is correct |
46 |
Correct |
1 ms |
292 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
292 KB |
Output is correct |
52 |
Correct |
0 ms |
292 KB |
Output is correct |
53 |
Correct |
0 ms |
292 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
288 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
288 KB |
Output is correct |
60 |
Correct |
0 ms |
292 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
354 ms |
27412 KB |
Output is correct |
64 |
Correct |
262 ms |
11980 KB |
Output is correct |
65 |
Correct |
313 ms |
26956 KB |
Output is correct |
66 |
Correct |
273 ms |
11968 KB |
Output is correct |
67 |
Correct |
270 ms |
13448 KB |
Output is correct |
68 |
Correct |
270 ms |
15744 KB |
Output is correct |
69 |
Correct |
310 ms |
27516 KB |
Output is correct |
70 |
Correct |
262 ms |
12012 KB |
Output is correct |
71 |
Correct |
298 ms |
13388 KB |
Output is correct |
72 |
Correct |
277 ms |
15760 KB |
Output is correct |
73 |
Correct |
316 ms |
27432 KB |
Output is correct |
74 |
Correct |
270 ms |
12108 KB |
Output is correct |
75 |
Correct |
270 ms |
13280 KB |
Output is correct |
76 |
Correct |
290 ms |
15696 KB |
Output is correct |
77 |
Correct |
298 ms |
27488 KB |
Output is correct |
78 |
Correct |
168 ms |
19660 KB |
Output is correct |
79 |
Correct |
174 ms |
19712 KB |
Output is correct |
80 |
Correct |
247 ms |
19768 KB |
Output is correct |
81 |
Correct |
271 ms |
19728 KB |
Output is correct |
82 |
Correct |
127 ms |
11980 KB |
Output is correct |
83 |
Correct |
250 ms |
12012 KB |
Output is correct |
84 |
Correct |
142 ms |
11916 KB |
Output is correct |
85 |
Correct |
325 ms |
28504 KB |
Output is correct |
86 |
Correct |
325 ms |
28544 KB |
Output is correct |
87 |
Correct |
181 ms |
20720 KB |
Output is correct |
88 |
Correct |
273 ms |
20816 KB |
Output is correct |