結果

問題 No.4 おもりと天秤
ユーザー koukonko
提出日時 2015-12-24 23:22:16
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 810 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 75,416 KB
実行使用メモリ 52,492 KB
最終ジャッジ日時 2024-09-18 23:02:47
合計ジャッジ時間 4,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));

		try {
			int N = Integer.parseInt(buff.readLine());
			String[] box = buff.readLine().split(" ");
			int[] w = new int[N];

			for (int i = 0; i < N; ++i) {
				w[i] = Integer.parseInt(box[i]);
			}
			Arrays.sort(w);

			int left = 0, right = 0, index = N - 1;
			while (N-- > 0) {
				if (left < right) {
					left += w[index--];
				} else {
					right += w[index--];
				}
			}

			if (right == left) {
				System.out.println("possible");
			} else {
				System.out.println("impossible");
			}
		} catch (Exception e) {
			e.getStackTrace();
		}
	}

}
0