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
//#include <bits/stdc++.h>
//using namespace std;
//
//#define ll long long
//
//int main() {
//  ios::sync_with_stdio(false);
//  cin.tie(nullptr);
//
//
//}

#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll nums;
  ll range;
  ll jobs;
  cin >> nums >> range >> jobs;

  ll sum[nums + 1];
  sum[0] = 0;
  for (ll i = 1; i <= nums; i++) {
    ll temp;
    cin >> temp;
    sum[i] = sum[i - 1] + temp;
  }

  ll dp[nums + 1];
  while (jobs--) {
    ll L;
    ll R;
    cin >> L >> R;
    L--;
    for (ll i = 0; i < R - L + 1; i++) dp[i] = 0;
    for (ll i = range; i < R - L + 1; i++) {
      dp[i] = max(dp[i - 1], dp[i - range] + sum[i + L] - sum[i + L - range]);
    }
    cout << dp[R - L] << "\n";
  }
}