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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>     // std::cout
#include <algorithm>    // std::sort
#include <vector>       // std::vector
#include <set>
#include <cmath>
#include <string>
#include <map>
#include <cassert>
#include <functional>
#include <tuple>
#include <numeric>
#include <queue>
#include <list>

using namespace std;

#define DEBUG 0
#define MAXN 300010
#define MAXK 30

int n,k,z,l,r;
long long sum[MAXN];
long long d[MAXN];

long long solve(){

    if (DEBUG){
        cout << endl << "Solve " << l << ' ' << r << endl;
        for (int i=l; i<=r; ++i){
            cout << i << '\t';
        }
        cout << endl;
    }
   
    for (int i=l; i<=r; ++i){
        if (i-l+1 < k) d[i]=0;
        else d[i] = max(d[i-1], max(d[i-k] + sum[i] - sum[i-k], (long long)0));
        if (DEBUG) cout << d[i] << '\t';
    }
    if (DEBUG) cout << endl;

    long long res = d[r];
    for (int i=l; i<=r; ++i){
        d[i]=0;
    }
    return res;
}

int main() {
    scanf("%d%d%d", &n, &k, &z);
    for (int i=1; i<=n; ++i){
        int a;
        scanf("%d", &a);
        sum[i] = sum[i-1] + a;
    }
    while (z--){
        scanf("%d%d", &l, &r);
        printf("%lld\n", solve());
    }
    return 0;
}