結果

問題 No.216 FAC
ユーザー mobius_bkstmobius_bkst
提出日時 2015-05-26 22:57:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 1,667 bytes
コンパイル時間 3,635 ms
コンパイル使用メモリ 80,224 KB
実行使用メモリ 37,240 KB
最終ジャッジ日時 2024-04-23 01:20:12
合計ジャッジ時間 6,035 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
36,984 KB
testcase_01 AC 51 ms
36,928 KB
testcase_02 AC 54 ms
37,164 KB
testcase_03 AC 55 ms
37,220 KB
testcase_04 AC 51 ms
36,824 KB
testcase_05 AC 53 ms
36,708 KB
testcase_06 AC 53 ms
37,184 KB
testcase_07 AC 52 ms
37,160 KB
testcase_08 AC 52 ms
37,144 KB
testcase_09 AC 53 ms
36,892 KB
testcase_10 AC 52 ms
37,124 KB
testcase_11 AC 51 ms
37,144 KB
testcase_12 AC 52 ms
37,072 KB
testcase_13 AC 56 ms
36,888 KB
testcase_14 AC 51 ms
36,824 KB
testcase_15 AC 54 ms
37,100 KB
testcase_16 AC 57 ms
37,192 KB
testcase_17 AC 58 ms
37,180 KB
testcase_18 AC 52 ms
37,116 KB
testcase_19 AC 53 ms
37,240 KB
testcase_20 AC 56 ms
37,148 KB
testcase_21 AC 51 ms
37,152 KB
testcase_22 AC 54 ms
37,152 KB
testcase_23 AC 55 ms
37,108 KB
testcase_24 AC 53 ms
37,112 KB
testcase_25 AC 52 ms
37,144 KB
testcase_26 AC 54 ms
37,076 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(b[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