Cod sursa(job #3252271)

Utilizator Gabriel_DaescuDaescu Gabriel Florin Gabriel_Daescu Data 28 octombrie 2024 22:46:43
Problema Teren Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>
#define NMAX 302
using namespace std;
ifstream  fin("teren.in");
ofstream fout("teren.out");
int N,M,X,st,dr,nr,lmax,Sp[NMAX][NMAX];

void citire()
{
    fin>>N>>M>>X;

    for(int i=1; i<=N; i++)
    {
        for(int j=1; j<=M; j++)
        {
            fin>>Sp[i][j];
            Sp[i][j]+=Sp[i-1][j];
        }
    }
}

int main()
{
    citire();

    lmax=0;
    for(int i=1; i<=N; i++)
    {
        for(int j=i; j<=N; j++)
        {
            dr=nr=0;
            st=1;

            while(dr<M)
            {
                dr++;
                nr+=Sp[j][dr]-Sp[i-1][dr];

                while(nr>X)
                {
                    nr-=(Sp[j][st]-Sp[i-1][st]);
                    st++;
                }

                if(nr<=X)
                {
                   lmax=max(lmax,(j-i+1)*(dr-st+1));
                }
            }
        }
    }

    fout<< lmax << "\n";

    return 0;
}