-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
52 lines (43 loc) · 1.05 KB
/
D.cpp
File metadata and controls
52 lines (43 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
48
49
50
51
52
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main() {
string first_line;
getline(cin, first_line);
stringstream ss(first_line);
int n, k;
ss >> n >> k;
vector<vector<int>> a(n + 1, vector<int>(n + 1, 0));
vector<int> h(n + 1, 0);
vector<int> v(n + 2, 0);
for (int s = 1; s < n; ++s) {
string line;
getline(cin, line);
stringstream ss(line);
for (int t = s + 1; t <= n; ++t) {
ss >> a[s][t];
h[s] += a[s][t];
}
}
for (int t = 2; t <= n; ++t) {
for (int s = 1; s < n; ++s) {
v[t] += a[s][t];
}
}
int window = 0;
for (int i = 1; i <= k; ++i) {
window += h[i];
}
// cout << "window = " << window << endl;
int ans = window;
for (int i = 2; i <= n - k; ++i) {
window -= v[i];
window += h[i + k - 1];
// cout << "window = " << window << endl;
ans = max(window, ans);
}
cout << ans << endl;
return 0;
}