## Editorial for Another Random Contest 1 P2 - Two Sequences

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**Author:

#### Subtask 1

For every query, enumerate from to and determine the value for every position using prefix sum.

**Time Complexity:**

#### Subtask 2

Let's call and .

Since all numbers in and are positive, will always increase and will always decrease as moves to the right. One can interpret two expressions as increasing and decreasing functions. It is clear that the minimum will occur when the two functions intersect. Binary search can be used to find the intersection or points closest to the intersection. If , binary search right, and if , binary search left.

**Time Complexity:**

## Comments