let get_int () = Scanf.scanf " %d" (fun x -> x) ;; let () = let n = get_int () in let a = Array.init (n+1) (fun _ -> get_int ()) in let b = Array.init (n+1) (fun _ -> get_int ()) in let d = Array.init n (fun _ -> get_int ()) in Array.sort (fun x y -> compare y x) d; let l = ref 0 in let r = ref (n+1) in while !r - !l > 1 do let m = (!l + !r)/2 in let dp = Array.make_matrix (m+1) (m+1) false in dp.(0).(0) <- true; for i=0 to m-1 do for j=0 to m-1 do if i+j= d.(i+j+n-m) then dp.(i+1).(j) <- true; if a.(i) + b.(j+1) >= d.(i+j+n-m) then dp.(i).(j+1) <- true; end done done; let mx = ref 0 in for i=0 to m do for j=0 to m do if dp.(i).(j) then mx := max !mx (i+j) done done; if !mx = m then l := m else r := m done; Printf.printf "%d\n" !l ;;