Two Arrays and Sum of Functions

CodeForces - 1165E