import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author ijxjdjd
*/
public class remittance {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
remittanc solver = new remittanc();
solver.solve(1, in, out);
out.close();
}
static class remittanc {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int N = in.nextInt();
long last = 0;
long max = 0;
long[] A = new long[N];
long[] B = new long[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
B[i] = in.nextInt();
}
boolean first = true;
// while (last > 0 || first) {
for (int j = 0; j < 20; j++) {
for (int i = 0; i < N; i++) {
if (A[i] > B[i]) {
if (A[i] - 2 * ((A[i] - B[i] + 1) / 2) < 0) {
continue;
}
last = ((A[i] - B[i]) + 1) / 2;
A[i] -= last * 2;
} else {
last = 0;
}
A[(i + 1) % N] += last;
}
// }
}
for (int i = 0; i < N; i++) {
if (A[i] != B[i]) {
out.println("No");
return;
}
}
out.println("Yes");
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
9476 KB |
Output is correct |
2 |
Correct |
85 ms |
9692 KB |
Output is correct |
3 |
Correct |
85 ms |
9728 KB |
Output is correct |
4 |
Correct |
84 ms |
9536 KB |
Output is correct |
5 |
Correct |
87 ms |
9644 KB |
Output is correct |
6 |
Correct |
84 ms |
9604 KB |
Output is correct |
7 |
Correct |
85 ms |
9548 KB |
Output is correct |
8 |
Correct |
86 ms |
9664 KB |
Output is correct |
9 |
Correct |
84 ms |
9436 KB |
Output is correct |
10 |
Correct |
87 ms |
9672 KB |
Output is correct |
11 |
Correct |
86 ms |
9664 KB |
Output is correct |
12 |
Correct |
90 ms |
9872 KB |
Output is correct |
13 |
Correct |
97 ms |
9564 KB |
Output is correct |
14 |
Correct |
96 ms |
9668 KB |
Output is correct |
15 |
Correct |
86 ms |
9444 KB |
Output is correct |
16 |
Correct |
87 ms |
9728 KB |
Output is correct |
17 |
Correct |
86 ms |
9632 KB |
Output is correct |
18 |
Correct |
86 ms |
9748 KB |
Output is correct |
19 |
Correct |
85 ms |
9508 KB |
Output is correct |
20 |
Correct |
89 ms |
9828 KB |
Output is correct |
21 |
Correct |
86 ms |
9740 KB |
Output is correct |
22 |
Correct |
87 ms |
9744 KB |
Output is correct |
23 |
Correct |
85 ms |
9596 KB |
Output is correct |
24 |
Correct |
83 ms |
9832 KB |
Output is correct |
25 |
Correct |
85 ms |
9700 KB |
Output is correct |
26 |
Correct |
85 ms |
9588 KB |
Output is correct |
27 |
Correct |
83 ms |
9580 KB |
Output is correct |
28 |
Correct |
84 ms |
9608 KB |
Output is correct |
29 |
Correct |
84 ms |
9836 KB |
Output is correct |
30 |
Correct |
89 ms |
10020 KB |
Output is correct |
31 |
Correct |
83 ms |
9484 KB |
Output is correct |
32 |
Correct |
87 ms |
9740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
9476 KB |
Output is correct |
2 |
Correct |
85 ms |
9692 KB |
Output is correct |
3 |
Correct |
85 ms |
9728 KB |
Output is correct |
4 |
Correct |
84 ms |
9536 KB |
Output is correct |
5 |
Correct |
87 ms |
9644 KB |
Output is correct |
6 |
Correct |
84 ms |
9604 KB |
Output is correct |
7 |
Correct |
85 ms |
9548 KB |
Output is correct |
8 |
Correct |
86 ms |
9664 KB |
Output is correct |
9 |
Correct |
84 ms |
9436 KB |
Output is correct |
10 |
Correct |
87 ms |
9672 KB |
Output is correct |
11 |
Correct |
86 ms |
9664 KB |
Output is correct |
12 |
Correct |
90 ms |
9872 KB |
Output is correct |
13 |
Correct |
97 ms |
9564 KB |
Output is correct |
14 |
Correct |
96 ms |
9668 KB |
Output is correct |
15 |
Correct |
86 ms |
9444 KB |
Output is correct |
16 |
Correct |
87 ms |
9728 KB |
Output is correct |
17 |
Correct |
86 ms |
9632 KB |
Output is correct |
18 |
Correct |
86 ms |
9748 KB |
Output is correct |
19 |
Correct |
85 ms |
9508 KB |
Output is correct |
20 |
Correct |
89 ms |
9828 KB |
Output is correct |
21 |
Correct |
86 ms |
9740 KB |
Output is correct |
22 |
Correct |
87 ms |
9744 KB |
Output is correct |
23 |
Correct |
85 ms |
9596 KB |
Output is correct |
24 |
Correct |
83 ms |
9832 KB |
Output is correct |
25 |
Correct |
85 ms |
9700 KB |
Output is correct |
26 |
Correct |
85 ms |
9588 KB |
Output is correct |
27 |
Correct |
83 ms |
9580 KB |
Output is correct |
28 |
Correct |
84 ms |
9608 KB |
Output is correct |
29 |
Correct |
84 ms |
9836 KB |
Output is correct |
30 |
Correct |
89 ms |
10020 KB |
Output is correct |
31 |
Correct |
83 ms |
9484 KB |
Output is correct |
32 |
Correct |
87 ms |
9740 KB |
Output is correct |
33 |
Correct |
83 ms |
9608 KB |
Output is correct |
34 |
Correct |
88 ms |
9688 KB |
Output is correct |
35 |
Correct |
85 ms |
9828 KB |
Output is correct |
36 |
Correct |
84 ms |
9612 KB |
Output is correct |
37 |
Correct |
85 ms |
9644 KB |
Output is correct |
38 |
Correct |
83 ms |
9728 KB |
Output is correct |
39 |
Correct |
87 ms |
9616 KB |
Output is correct |
40 |
Correct |
85 ms |
9648 KB |
Output is correct |
41 |
Correct |
83 ms |
9756 KB |
Output is correct |
42 |
Correct |
86 ms |
9680 KB |
Output is correct |
43 |
Correct |
84 ms |
9504 KB |
Output is correct |
44 |
Correct |
86 ms |
9716 KB |
Output is correct |
45 |
Correct |
86 ms |
9732 KB |
Output is correct |
46 |
Correct |
84 ms |
9648 KB |
Output is correct |
47 |
Correct |
86 ms |
9716 KB |
Output is correct |
48 |
Correct |
91 ms |
9800 KB |
Output is correct |
49 |
Correct |
85 ms |
9716 KB |
Output is correct |
50 |
Correct |
86 ms |
9584 KB |
Output is correct |
51 |
Correct |
86 ms |
9740 KB |
Output is correct |
52 |
Correct |
83 ms |
9676 KB |
Output is correct |
53 |
Correct |
88 ms |
9728 KB |
Output is correct |
54 |
Correct |
87 ms |
9480 KB |
Output is correct |
55 |
Correct |
86 ms |
9560 KB |
Output is correct |
56 |
Correct |
86 ms |
9672 KB |
Output is correct |
57 |
Correct |
88 ms |
9704 KB |
Output is correct |
58 |
Correct |
85 ms |
9592 KB |
Output is correct |
59 |
Correct |
90 ms |
9680 KB |
Output is correct |
60 |
Correct |
88 ms |
9736 KB |
Output is correct |
61 |
Correct |
85 ms |
9708 KB |
Output is correct |
62 |
Correct |
87 ms |
9760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
9476 KB |
Output is correct |
2 |
Correct |
85 ms |
9692 KB |
Output is correct |
3 |
Correct |
85 ms |
9728 KB |
Output is correct |
4 |
Correct |
84 ms |
9536 KB |
Output is correct |
5 |
Correct |
87 ms |
9644 KB |
Output is correct |
6 |
Correct |
84 ms |
9604 KB |
Output is correct |
7 |
Correct |
85 ms |
9548 KB |
Output is correct |
8 |
Correct |
86 ms |
9664 KB |
Output is correct |
9 |
Correct |
84 ms |
9436 KB |
Output is correct |
10 |
Correct |
87 ms |
9672 KB |
Output is correct |
11 |
Correct |
86 ms |
9664 KB |
Output is correct |
12 |
Correct |
90 ms |
9872 KB |
Output is correct |
13 |
Correct |
97 ms |
9564 KB |
Output is correct |
14 |
Correct |
96 ms |
9668 KB |
Output is correct |
15 |
Correct |
86 ms |
9444 KB |
Output is correct |
16 |
Correct |
87 ms |
9728 KB |
Output is correct |
17 |
Correct |
86 ms |
9632 KB |
Output is correct |
18 |
Correct |
86 ms |
9748 KB |
Output is correct |
19 |
Correct |
85 ms |
9508 KB |
Output is correct |
20 |
Correct |
89 ms |
9828 KB |
Output is correct |
21 |
Correct |
86 ms |
9740 KB |
Output is correct |
22 |
Correct |
87 ms |
9744 KB |
Output is correct |
23 |
Correct |
85 ms |
9596 KB |
Output is correct |
24 |
Correct |
83 ms |
9832 KB |
Output is correct |
25 |
Correct |
85 ms |
9700 KB |
Output is correct |
26 |
Correct |
85 ms |
9588 KB |
Output is correct |
27 |
Correct |
83 ms |
9580 KB |
Output is correct |
28 |
Correct |
84 ms |
9608 KB |
Output is correct |
29 |
Correct |
84 ms |
9836 KB |
Output is correct |
30 |
Correct |
89 ms |
10020 KB |
Output is correct |
31 |
Correct |
83 ms |
9484 KB |
Output is correct |
32 |
Correct |
87 ms |
9740 KB |
Output is correct |
33 |
Correct |
83 ms |
9608 KB |
Output is correct |
34 |
Correct |
88 ms |
9688 KB |
Output is correct |
35 |
Correct |
85 ms |
9828 KB |
Output is correct |
36 |
Correct |
84 ms |
9612 KB |
Output is correct |
37 |
Correct |
85 ms |
9644 KB |
Output is correct |
38 |
Correct |
83 ms |
9728 KB |
Output is correct |
39 |
Correct |
87 ms |
9616 KB |
Output is correct |
40 |
Correct |
85 ms |
9648 KB |
Output is correct |
41 |
Correct |
83 ms |
9756 KB |
Output is correct |
42 |
Correct |
86 ms |
9680 KB |
Output is correct |
43 |
Correct |
84 ms |
9504 KB |
Output is correct |
44 |
Correct |
86 ms |
9716 KB |
Output is correct |
45 |
Correct |
86 ms |
9732 KB |
Output is correct |
46 |
Correct |
84 ms |
9648 KB |
Output is correct |
47 |
Correct |
86 ms |
9716 KB |
Output is correct |
48 |
Correct |
91 ms |
9800 KB |
Output is correct |
49 |
Correct |
85 ms |
9716 KB |
Output is correct |
50 |
Correct |
86 ms |
9584 KB |
Output is correct |
51 |
Correct |
86 ms |
9740 KB |
Output is correct |
52 |
Correct |
83 ms |
9676 KB |
Output is correct |
53 |
Correct |
88 ms |
9728 KB |
Output is correct |
54 |
Correct |
87 ms |
9480 KB |
Output is correct |
55 |
Correct |
86 ms |
9560 KB |
Output is correct |
56 |
Correct |
86 ms |
9672 KB |
Output is correct |
57 |
Correct |
88 ms |
9704 KB |
Output is correct |
58 |
Correct |
85 ms |
9592 KB |
Output is correct |
59 |
Correct |
90 ms |
9680 KB |
Output is correct |
60 |
Correct |
88 ms |
9736 KB |
Output is correct |
61 |
Correct |
85 ms |
9708 KB |
Output is correct |
62 |
Correct |
87 ms |
9760 KB |
Output is correct |
63 |
Correct |
959 ms |
99212 KB |
Output is correct |
64 |
Correct |
805 ms |
102916 KB |
Output is correct |
65 |
Correct |
935 ms |
117140 KB |
Output is correct |
66 |
Correct |
756 ms |
103680 KB |
Output is correct |
67 |
Correct |
797 ms |
104796 KB |
Output is correct |
68 |
Correct |
785 ms |
106328 KB |
Output is correct |
69 |
Correct |
942 ms |
118184 KB |
Output is correct |
70 |
Correct |
774 ms |
103084 KB |
Output is correct |
71 |
Correct |
831 ms |
104296 KB |
Output is correct |
72 |
Correct |
801 ms |
105260 KB |
Output is correct |
73 |
Correct |
934 ms |
116524 KB |
Output is correct |
74 |
Correct |
771 ms |
103000 KB |
Output is correct |
75 |
Correct |
863 ms |
104536 KB |
Output is correct |
76 |
Correct |
798 ms |
106948 KB |
Output is correct |
77 |
Correct |
948 ms |
117732 KB |
Output is correct |
78 |
Correct |
977 ms |
110776 KB |
Output is correct |
79 |
Correct |
968 ms |
111224 KB |
Output is correct |
80 |
Correct |
827 ms |
110664 KB |
Output is correct |
81 |
Correct |
908 ms |
110448 KB |
Output is correct |
82 |
Correct |
694 ms |
102776 KB |
Output is correct |
83 |
Correct |
750 ms |
102732 KB |
Output is correct |
84 |
Correct |
738 ms |
102400 KB |
Output is correct |
85 |
Correct |
947 ms |
120336 KB |
Output is correct |
86 |
Correct |
930 ms |
119148 KB |
Output is correct |
87 |
Correct |
874 ms |
110960 KB |
Output is correct |
88 |
Correct |
884 ms |
111920 KB |
Output is correct |