結果

問題 No.216 FAC
コンテスト
ユーザー YamaKasa
提出日時 2018-04-30 00:33:15
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 76 ms / 1,000 ms
コード長 795 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,830 ms
コンパイル使用メモリ 87,400 KB
実行使用メモリ 43,264 KB
最終ジャッジ日時 2026-03-16 05:50:48
合計ジャッジ時間 4,631 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.HashMap;
import java.util.Scanner;

public class Main {
	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];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		for(int i = 0; i < N; i++) {
			b[i] = scan.nextInt();
		}
		scan.close();
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		int k = 0;
		for(int i = 0; i < N; i++) {
			if(b[i] == 0) {
				k += a[i];
			}else {
				if(map.get(b[i]) != null) {
					map.put(b[i], map.get(b[i]) + a[i]);
				}else {
					map.put(b[i], a[i]);
				}
			}
		}
		for(int t : map.keySet()) {
			if(k < map.get(t)) {
				System.out.println("NO");
				System.exit(0);
			}
		}
		System.out.println("YES");
	}
}
0