Cod sursa(job #2347772)

Utilizator FastmateiMatei Mocanu Fastmatei Data 19 februarie 2019 08:45:18
Problema Teren Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;

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

int a[305][305],n,m;
int t[305];

int main()
{
    int x,i,j,s,smax=-1,l1,l2,h;
    fin>>n>>m>>x;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            {
                fin>>a[i][j];
                a[i][j]+=a[i-1][j];
            }
    for(l1=1;l1<=n;l1++)
        for(l2=l1;l2<=n;l2++)
        {
            h=l2-l1+1;
            s=0;
            for(j=1;j<=m;j++)
                t[j]=a[l2][j]-a[l1-1][j];
            j=1;
            for(i=1;i<=m;i++)
            {
                s+=t[i];
                while(s>x)
                {
                    s-=t[j];
                    j++;
                }
                smax=max(smax,(i-j+1)*h);
            }
        }
    fout<<smax;
    return 0;
}