Cod sursa(job #1596174)

Utilizator sucureiSucureiRobert sucurei Data 10 februarie 2016 20:39:38
Problema Teren Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>

using namespace std;
ifstream f("teren.in");
ofstream g("teren.out");
int a[301][301],i,j,x,st,k,n,m,Max,s,t;
int main()
{
    f>>n>>m>>x;
    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++)
        {

            f>>a[i][j];

            a[i][j]+=a[i-1][j];
        }
    for(i=1; i<=n; i++)
    {
        for(j=i; j<=n; j++)
        {
            st=1;
            s=0;
            for(k=1; k<=m; k++)
            {

                t=a[j][k]-a[i-1][k];
                if(s+t<=x)
                    s+=t;
                else
                {
                    while(s+t>x&&st<k)
                    {
                        s-=(a[j][st]-a[i-1][st]);
                        st++;
                    }
                    s=s+t;
                }
                if(s<=x&&(j-i+1)*(k-st+1)>Max)
                    Max=(j-i+1)*(k-st+1);

            }
        }
    }
    g<<Max;
    return 0;
}