結果

問題 No.4 おもりと天秤
ユーザー koukonkokoukonko
提出日時 2015-12-24 23:22:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 810 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 74,688 KB
実行使用メモリ 53,652 KB
最終ジャッジ日時 2023-10-19 02:56:35
合計ジャッジ時間 4,394 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,544 KB
testcase_01 AC 54 ms
53,536 KB
testcase_02 AC 55 ms
53,552 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 55 ms
53,540 KB
testcase_06 AC 54 ms
53,540 KB
testcase_07 AC 55 ms
53,548 KB
testcase_08 AC 56 ms
52,664 KB
testcase_09 AC 55 ms
52,624 KB
testcase_10 AC 54 ms
53,552 KB
testcase_11 AC 54 ms
53,544 KB
testcase_12 AC 55 ms
53,548 KB
testcase_13 AC 55 ms
52,644 KB
testcase_14 AC 54 ms
53,552 KB
testcase_15 AC 55 ms
53,556 KB
testcase_16 AC 55 ms
53,556 KB
testcase_17 WA -
testcase_18 AC 54 ms
53,548 KB
testcase_19 AC 55 ms
53,556 KB
testcase_20 AC 55 ms
53,552 KB
testcase_21 AC 56 ms
52,664 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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