Given three arrays A, B, and C of size n, m, and m respectively (1-based indexed). A function F(i) is defined as -
F(i) = minimum_of(⌈ Ai / B1 ⌉ * C1 , ⌈ Ai / B2 ⌉ * C2 , ⌈ Ai / B3 ⌉ * C3 , .... , ⌈ Ai / Bm ⌉ * Cm)
where ⌈x⌉ is defined as the ceiling function. For example : ⌈2.3⌉ = 3, ⌈3.9⌉ = 4 and ⌈3⌉ = 3.
Find the value of F(1) + F(2) + F(3) + ..... + F(n).
Constraints: 1 <= n, m, Ai, Bi, Ci <= 1000000
How do I solve this question in better than O(N*N) time complexity? The question is from a past onsite final. Problem link