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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main() {
int n;
cin >> n;
ll cnt[55][55];
memset(cnt, 0, sizeof(cnt));
rep(i, n) {
rep(j, n) {
cin >> cnt[i][j];
}
}
rep(i, n) {
REP(j, 1, n) {
cnt[i][j] += cnt[i][j-1];
}
}
REP(i, 1, n) {
rep(j, n) {
cnt[i][j] += cnt[i-1][j];
}
}
map<int, int> m;
rep(i, n) {
rep(j, n) {
rep(k, n) {
if(i + k >= n) continue;
rep(l, n) {
if(j + l >= n) continue;
int res = cnt[i+k][j+l];
if(i - 1 >= 0) {
res -= cnt[i-1][j+l];
}
if(j - 1 >= 0) {
res -= cnt[i+k][j-1];
}
if(i - 1 >= 0 && j - 1 >= 0) {
res += cnt[i-1][j-1];
}
m[(k + 1) * (l + 1)] = max(m[(k + 1) * (l + 1)] , res);
}
}
}
}
int Q;
cin >> Q;
rep(q, Q) {
int p;
cin >> p;
int ans = 0;
rep(i, p + 1) {
ans = max(ans, m[i]);
}
cout << ans << endl;
}
return 0;
}
|