Comments

Problem $$$F$$$ can be solved using $$$Binary\ Lifting$$$ although it is not optimal.

Idea
Sample Code

Can we solve $$$E$$$ using $$$DP$$$? I tried solving using $$$DP$$$ in the contest time but got $$$wa$$$ on pretest $$$6$$$. My $$$DP$$$ idea was pretty simple.

code

Still not understanding why got $$$WA$$$. Please help

N.B: It is failing on cases like

6

18 8 1 4 6 16

An integer takes 4 Bytes of memory. So you are taking ((5e6+5)*2+1e6+5))*4 B=44000060B=41.96MB memory

SquareRoot Decomposition approach for D: 61667541