let list_group_by cmp lst = let rec list_group_by' lst result = match lst with | [] -> result | x::xs -> let value = cmp x in let lst1, lst2 = List.partition (fun v -> value = cmp v) lst in list_group_by' lst2 ((value, lst1)::result) in list_group_by' lst [] let list_sum_by f lst = List.fold_left (fun e1 e2 -> e1 + (f e2)) 0 lst let list_max_by f lst = let rec list_max_by' lst result = match lst with | [] -> result | x::xs -> let v = f x in let result = max result v in list_max_by' xs result in if (List.length lst) <= 0 then failwith "list_max_by" else list_max_by' (List.tl lst) (f (List.hd lst)) let solve a_lst b_lst = let ab_lst = List.combine a_lst b_lst in let other_score = List.filter (fun (a, b) -> b <> 0) ab_lst |> fun lst -> match lst with | [] -> 0 | _ -> list_group_by (fun (_, b) -> b) lst |> List.map (fun (b, ab_lst) -> list_sum_by (fun (a, b) -> a) ab_lst) |> list_max_by (fun i -> i) and k_score = List.filter (fun (a, b) -> b = 0) ab_lst |> fun lst -> match lst with | [] -> 0 | _ -> list_sum_by (fun (a, b) -> a) lst in if k_score >= other_score then "YES" else "NO" let () = let _ = read_line () and a_lst = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string and b_lst = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string in solve a_lst b_lst |> print_endline