# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
170076 | ijxjdjd | 송금 (JOI19_remittance) | Java | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileInputStream;
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 Main {
public static void main(String[] args) {
InputStream inputStream;
try {
inputStream = new FileInputStream("remittance.in");
} catch (IOException e) {
throw new RuntimeException(e);
}
OutputStream outputStream;
try {
outputStream = new FileOutputStream("remittance.out");
} catch (IOException e) {
throw new RuntimeException(e);
}
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
remittance solver = new remittance();
solver.solve(1, in, out);
out.close();
}
static class remittance {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int N = in.nextInt();
long[] val = new long[N];
long last = 0;
long max = 0;
for (int i = 0; i < N; i++) {
val[i] = in.nextInt() - in.nextInt();
max = Math.max(val[i], max);
}
boolean first = true;
while (last > 1 || first) {
first = false;
max = 0;
for (int i = 0; i < N; i++) {
val[i] += last;
if (val[i] > 0) {
last = val[i] / 2;
val[i] %= 2;
} else {
last = 0;
}
max = Math.max(val[i], max);
}
}
for (int i = 0; i < N; i++) {
if (val[i] != 0) {
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());
}
}
}