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
62
#include <bits/stdtr1c++.h>

#define F first
#define S second
#define ll long long
#define ld long double
#define vi vector < int >
#define pb push_back
#define sz(x) int((x).size())
#define pii pair < int, int >
#define all(x) (x).begin(), (x).end()
#define vpii vector < pii >
#define fenwick(x) ((x) & -(x))
#define debug(x) cout << "[ " << #x << " ]: " << x << "\n";

using namespace std;

#define clog if (0) cerr

const int MAX = 3e5 + 213;

ll tab[MAX];
ll dp[MAX];
int N, M;

void solve(int l, int r)
{
    for (int i = l - 1; i <= r; ++i)
        dp[i] = 0;

    for (int i = l + M - 1; i <= r; ++i)
    {
        clog << dp[i - M] << "\t" << tab[i] << "\t" << tab[i - M] << "\n";
        dp[i] = max(dp[i], dp[i - M] + tab[i] - tab[i - M]);
        dp[i] = max(dp[i], dp[i - 1]);
        clog << "I= " << i << "\tDP[i]= " << dp[i] << "\n\n";
    }

    cout << dp[r] << "\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int T; cin >> N >> M >> T;

    for (int i = 1; i <= N; ++i)
    {
        cin >> tab[i];
        tab[i] += tab[i - 1];
    }

    while (T--)
    {
        int l, r; cin >> l >> r;
        solve(l, r);
    }


    return 0;
}