# Another Frog-Jumping problem SOLUTION September Circuits ’20

Page Contents

### Another Frog-Jumping

Note: This is an estimated issue. There is no accurate arrangement. You should locate the most ideal arrangement. If you don’t mind investigate the example clarification to guarantee that you comprehend the issue effectively. Likewise, make an effort not to utilize uniquely input, in light of the fact that the checker is specific on experiments to check your entries quicker. Attempt to check your code all alone.

Issue articulation

There are (N+1) stones, numbered (1 , 2 , … , N + 1). For each (i ( 1 ≤ I ≤ N )), the tallness of stone (i) is (h_i) and the estimation of stone (i) is (a_i). There is a frog who is at first on stone 1. He will rehash the accompanying activity some number of times to arrive at stone (N+1) : If the frog is presently on stone (i), he can bounce to the (j) – the stone if the entirety of the accompanying conditions are met:

(i ≤ j ≤ n)

The tallness of the bounce is close to the width of the hop. Here, the stature of the bounce is characterized as a most extreme (h_i , h_{i + 1} , … h_j ), and width as (j − I + 1).

The expense of the bounce is (sumlimits_{l=i}^{j}sumlimits_{r=i(l ne r)}^{j} a_l*a_r).

After, he will consequently go to (j + 1) – the stone.

Likewise, the frog has his fortunate number (k) and he needs to arrive at stone (N+1) in (k) steps so entirety of expenses was limited. Your assignment is to ascertain the base total of expenses for him and find ideal bounces.

Information design

The principal line contains two whole numbers (N) and (k) ((1≤N≤10^4,1≤k≤min(n, 50))) — the length of the clusters and the quantity of hops

The subsequent line contains (N) whole numbers (h_1,h_2,… ,h_n(1≤h_i≤n)) — the exhibit (h)

The third line contains (N) whole numbers (a_1,a_2,… ,a_n(1≤a_i≤10^5)) — the exhibit (a)

It is ensured that we can accomplish (N+1)- th stone in (k) steps.

Yield design

The primary line contains one whole number – the ideal aggregate of expenses. Next (k ) lines contain two numbers – sets (i_1, j_1, . . . i_k, j_k), where (l_1 = 1, r_k = n, i_t ≤ j_t) , and (l_t = r_{t−1} + 1) for all (t>1)– the bounces of the frog.

Decision and scoring :

There are 6 test cases(with test). Your score will be determined by the accompanying standard: for each non-test experiment, you will get (min(20, 20*frac{ja+1}{pa+1})) scores, and 0 scores for the example. Here ja – jury’s whole of costs, dad – your total of expenses. On the off chance that your yield doesn’t concur with the yield design, you will get 0 scores on test.

Test INPUT

10 4

1 3 2 1 2 3 1 2

Test OUTPUT

16

1 3

4 5

6 7

8 10

Clarification

We can see that the principal hop from 1 to 3 met the entirety of the previously mentioned conditions. The most extreme in this range is 3, which is close to the width. The expense of this bounce is 6. Presently frog on the fourth stone.

We can see that the main hop from 4 to 5 met the entirety of the previously mentioned conditions. The most extreme in this range is 2, which is close to the width. The expense of this hop is 2. Presently frog on the sixth stone.

We can see that the principal bounce from 6 to 7 met the entirety of the previously mentioned conditions. The greatest in this range is 2, which is close to the width. The expense of this bounce is 2. Presently frog on the eighth stone.

We can see that the primary hop from 8 to 10 met the entirety of the previously mentioned conditions. The most extreme in this range is 3, which is close to the width. The expense of this bounce is 6. Presently frog on the eleventh stone and finish.

Absolutely we have 6+2+2+6=16.