1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nd second
#define st first
#define mp make_pair
long long dp2[100009];
long long dp[100009];
long long pre[100009];
int tab[100009];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k, q;
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>tab[i];
        pre[i]=pre[i-1] + tab[i];
    }
    for(int j=0;j<q; j++)
    {
        int a, b;
        cin>>a>>b;
        for(int i=a+k-1;i<=b;i++)
        {
            dp[i] = pre[i]-pre[i-k]+dp2[i-k];
            dp2[i]= max(dp2[i-1], dp[i]);
        }
        cout<<max(dp[b], dp2[b])<<"\n";
        for(int i=a+k-1;i<=b;i++)
        {
            dp[i]=0;
            dp2[i]=0;
        }
    }
}