Pagini recente » Cod sursa (job #358519) | Cod sursa (job #2707547) | Cod sursa (job #1371854) | Cod sursa (job #2261925) | Cod sursa (job #2336940)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000, INF = 1e9;
int l[MAXN + 1][MAXN + 1], c[MAXN + 1][MAXN + 1], d[MAXN + 1][MAXN + 1];
int a[MAXN + 1][MAXN + 1];
int main() {
int n, k, i, j, there, remains, sol, s;
freopen ("ferma2.in", "r", stdin);
freopen ("ferma2.out", "w", stdout);
scanf ("%d%d", &n, &k);
for (i = 1; i <= n; i++)
for (j = 1; j <= i; j++)
scanf ("%d", &a[i][j]);
s = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
s += a[i][j];
l[i][j] = l[i][j - 1] + a[i][j];
c[i][j] = c[i - 1][j] + l[i][j];
d[i][j] = d[i - 1][j - 1] + l[i][j];
}
there = n - k;
sol = INF;
for (i = there; i <= n; i++)
for (j = there; j <= i; j++) {
remains = d[i][j] - c[i][j - there] + c[i - there][j - there] - d[i - there][j - there];
sol = min (sol, remains);
}
printf ("%d\n", s - sol);
return 0;
}