結果

問題 No.216 FAC
ユーザー mobius_bkstmobius_bkst
提出日時 2015-05-26 22:52:01
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,667 bytes
コンパイル時間 3,741 ms
コンパイル使用メモリ 75,432 KB
実行使用メモリ 51,824 KB
最終ジャッジ日時 2023-09-20 14:55:59
合計ジャッジ時間 6,217 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,420 KB
testcase_01 AC 46 ms
49,308 KB
testcase_02 AC 45 ms
49,120 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 43 ms
49,128 KB
testcase_07 AC 43 ms
47,156 KB
testcase_08 AC 43 ms
49,044 KB
testcase_09 WA -
testcase_10 AC 42 ms
49,308 KB
testcase_11 AC 43 ms
49,452 KB
testcase_12 AC 43 ms
49,228 KB
testcase_13 AC 43 ms
49,332 KB
testcase_14 WA -
testcase_15 AC 44 ms
49,296 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 43 ms
49,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class No216 {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            int N = Integer.parseInt(br.readLine());
            int[] a = strToIntArray(br.readLine());
            int[] b = strToIntArray(br.readLine());

            Map<Integer, Integer> map = new HashMap<Integer, Integer>();
            // 途中経過
            int sum = 0;
            for (int i = 0; i < N; i++) {
                if (b[i] == 0) {
                    sum += a[i];
                } else {
                    if (map.containsKey(a[i])) {
                        int score = map.get(b[i]);
                        map.put(b[i], a[i] + score);
                    } else {
                        map.put(b[i], a[i]);
                    }

                }
            }

            int max = 0;

            for (int i : map.values()) {
                max = Math.max(max, i);
            }
            if (max <= sum) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } catch (Exception e) {
            System.err.println("Error:" + e.getMessage());
        }
    }

    static int[] strToIntArray(String S) {
        String[] strArray = S.split(" ");
        int[] intArray = new int[strArray.length];
        for (int i = 0; i < strArray.length; i++) {
            intArray[i] = Integer.parseInt(strArray[i]);
        }
        return intArray;
    }
}
0