CF1601E.Phys Ed Online

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Students of one unknown college don't have PE courses. That's why qq of them decided to visit a gym nearby by themselves. The gym is open for nn days and has a ticket system. At the ii -th day, the cost of one ticket is equal to aia_i . You are free to buy more than one ticket per day.

You can activate a ticket purchased at day ii either at day ii or any day later. Each activated ticket is valid only for kk days. In other words, if you activate ticket at day tt , it will be valid only at days t,t+1,,t+k1t, t + 1, \dots, t + k - 1 .

You know that the jj -th student wants to visit the gym at each day from ljl_j to rjr_j inclusive. Each student will use the following strategy of visiting the gym at any day ii ( ljirjl_j \le i \le r_j ):

  1. person comes to a desk selling tickets placed near the entrance and buy several tickets with cost aia_i apiece (possibly, zero tickets);
  2. if the person has at least one activated and still valid ticket, they just go in. Otherwise, they activate one of tickets purchased today or earlier and go in.

Note that each student will visit gym only starting ljl_j , so each student has to buy at least one ticket at day ljl_j .

Help students to calculate the minimum amount of money they have to spend in order to go to the gym.

输入格式

The first line contains three integers nn , qq and kk ( 1n,q3000001 \le n, q \le 300\,000 ; 1kn1 \le k \le n ) — the number of days, the number of students and the number of days each ticket is still valid.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1091 \le a_i \le 10^9 ) — the cost of one ticket at the corresponding day.

Each of the next qq lines contains two integers lil_i and rir_i ( 1lirin1 \le l_i \le r_i \le n ) — the segment of days the corresponding student want to visit the gym.

输出格式

For each student, print the minimum possible amount of money they have to spend in order to go to the gym at desired days.

输入输出样例

  • 输入#1

    7 5 2
    2 15 6 3 7 5 6
    1 2
    3 7
    5 5
    7 7
    3 5

    输出#1

    2
    12
    7
    6
    9

说明/提示

Let's see how each student have to spend their money:

  • The first student should buy one ticket at day 11 .
  • The second student should buy one ticket at day 33 and two tickets at day 44 . Note that student can keep purchased tickets for the next days.
  • The third student should buy one ticket at day 55 .
  • The fourth student should buy one ticket at day 77 .
  • The fifth student should buy one ticket at day 33 and one at day 44 .
首页