-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum_coins.cpp
More file actions
46 lines (39 loc) · 801 Bytes
/
maximum_coins.cpp
File metadata and controls
46 lines (39 loc) · 801 Bytes
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
#include<iostream>
#include<vector>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
int N;
long long ans = 0;
cin >> N;
vector<vector<int> > v(N + 1);
for (int r = 1; r <= N; r++) {
vector<int> tmp(N + 1);
for (int c = 1; c <= N; c++) {
cin >> tmp[c];
}
v[r] = tmp;
}
for (int r = 1; r <= N; r++) {
long long candi = 0;
int t_r = r;
for (int c = 1; c <= N - r + 1; c++) {
candi += (long long)v[t_r][c];
t_r++;
}
if (candi > ans) ans = candi;
}
for (int c = 1; c <= N; c++) {
long long candi = 0;
int t_c = c;
for (int r = 1; r <= N - c + 1; r++) {
candi += (long long)v[r][t_c];
t_c++;
}
if (candi > ans) ans = candi;
}
cout << "Case #" << t << ": " << ans << "\n";
}
}