Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- ifstream in("tort.in");
- ofstream out("tort.out");
- #define cin in
- #define cout out
- const int nax = 505;
- int pre[nax][nax];
- int getSum(int x1, int y1, int x2, int y2) {
- return pre[x2][y2] - pre[x1 - 1][y2] - pre[x2][y1 - 1] + pre[x1 - 1][y1 - 1];
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, m, k;
- cin >> n >> m >> k;
- for (int i = 1; i <= n; ++i) {
- for (int j = 1; j <= m; ++j) {
- cin >> pre[i][j];
- pre[i][j] += pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
- }
- }
- int bestSum = 1e9;
- int countBest = 0;
- for (int w = 0; w <= k; ++w) {
- int h = k - w;
- // what remains? n - w && m = h
- int rN = n - w;
- int rM = m - h;
- for (int i = 1; i <= n; ++i) {
- for (int j = 1; j <= m; ++j) {
- int nxtX = i + rN - 1;
- int nxtY = j + rM - 1;
- if (nxtX > n || nxtY > m) {
- continue;
- }
- int curSum = getSum(i, j, nxtX, nxtY);
- if (curSum < bestSum) {
- bestSum = curSum;
- countBest = 1;
- }
- else if (curSum == bestSum) {
- countBest++;
- }
- }
- }
- }
- cout << pre[n][m] - bestSum << '\n' << countBest << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment