-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem0135.h
More file actions
47 lines (41 loc) · 1.05 KB
/
Problem0135.h
File metadata and controls
47 lines (41 loc) · 1.05 KB
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
//
// Created by Fengwei Zhang on 2021/7/20.
//
#ifndef ACWINGSOLUTION_PROBLEM0135_H
#define ACWINGSOLUTION_PROBLEM0135_H
#include <iostream>
#include <deque>
using namespace std;
class Problem0135 {
private:
int maxSeq(int nums[], int n, int m) {
int res = -0x3f3f3f3f;
deque<int> q;
for (int i = 0; i < n; ++i) {
while (!q.empty() && i - q.front() + 1 > m) {
q.pop_front();
}
if (!q.empty()) {
res = max(res, nums[i] - nums[q.front()]);
}
while (!q.empty() && nums[q.back()] >= nums[i]) {
q.pop_back();
}
q.push_back(i);
}
return res;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
int nums[n + 1];
nums[0] = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &nums[i]);
nums[i] += nums[i - 1];
}
printf("%d\n", maxSeq(nums, n + 1, m + 1));
return 0;
}
};
#endif //ACWINGSOLUTION_PROBLEM0135_H