結果

問題 No.178 美しいWhitespace (1)
ユーザー YamaKasa
提出日時 2018-05-18 15:06:21
言語 Java
(openjdk 23)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 74,468 KB
実行使用メモリ 44,072 KB
最終ジャッジ日時 2024-06-28 13:44:04
合計ジャッジ時間 8,188 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int []l = new int[N];
		for(int i = 0; i < N; i++) {
			int a = scan.nextInt();
			int b = scan.nextInt();
			l[i] = a + 4 * b;
		}
		scan.close();
		Arrays.sort(l);
		int max = l[N - 1];
		long c = 0;
		for(int i = 0; i < N - 1; i++) {
			if((max - l[i]) % 2 == 1) {
				System.out.println(-1);
				System.exit(0);
			}else {
				c += (max - l[i]) / 2;
			}
		}
		System.out.println(c);
	}
}
0