Cod sursa(job #2350838)

Utilizator radugheoRadu Mihai Gheorghe radugheo Data 21 februarie 2019 19:00:48
Problema Teren Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin  ("teren.in");
ofstream fout ("teren.out");

int n, m, x, i, j, st, dr, i1, i2, ar, sol, es, k;
int a[305][305];

int main(){
    fin >> n >> m >> x;
    for (i=1; i<=n; i++){
        for (j=1; j<=m; j++){
            fin >> k;
            a[i][j] = k + a[i-1][j] + a[i][j-1] - a[i-1][j-1];
        }
    }
    sol = -1;
    for (i1=1; i1<=n; i1++){
        for (i2=i1; i2<=n; i2++){
            st = 1;
            for (j=1; j<=m; j++){
                es = a[i2][j] - a[i2][st-1] - a[i1-1][j] + a[i1-1][st-1];
                while (es > x && st <= j){
                    st++;
                }
                ar = (i2 - i1 + 1)*(j - st + 1);
                sol = max (sol, ar);
            }
        }
    }
    fout << sol;
    return 0;
}