結果

問題 No.178 美しいWhitespace (1)
ユーザー ちよちゃん
提出日時 2016-06-07 00:36:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 3,403 ms
コンパイル使用メモリ 78,888 KB
実行使用メモリ 43,508 KB
最終ジャッジ日時 2024-10-08 16:54:57
合計ジャッジ時間 8,867 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Yuki178 {
	
	public static void main(String[] args) {
	
			Scanner scan = new Scanner(System.in);
			int n = scan.nextInt();
			int a[] = new int[n];
			int b[] = new int[n];
			boolean flg = true;
			
			ArrayList<Long> array = new ArrayList<Long>();
			
			for (int i = 0; i < n ; i++ ) {
				a[i] = scan.nextInt();
				b[i] = scan.nextInt();
				
			}
			scan.close();
			
		    long ans = 0;
			for (int i = 0; i < n ; i++ ) {
				ans = a[i] + 4 * b[i];
				array.add(ans);
			}
			
			Collections.sort(array);
			long max = Collections.max(array);
			
			long big_ans = 0;
			for(long num : array){
				big_ans += ((max - num) / 2);
				if((max - num) % 2 == 1){ 
					flg = false;
				}
			}

			if (flg == true){
				System.out.println(big_ans);
			} else {
				System.out.println(-1);
			}
	}

}
0