Cod sursa(job #2766288)

Utilizator AlexSerban21Serban Alexandru AlexSerban21 Data 31 iulie 2021 15:25:35
Problema Teren Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
using namespace std;
ifstream fin ("teren.in");
ofstream fout ("teren.out");
int n,m,y,i,j,x,su,a,b,c,d,e,f,maxc,v[301][301],s[301][301];
int main()
{
    fin>>n>>m>>y;
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=m; j++)
        {
            fin>>x;
            s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]+x;
            v[i][j]=x;
        }
    }
    for (a=1; a<=n; a++)
    {
        for (b=1; b<=m; b++)
        {
            if (v[a][b]==1)
                b++;
            for (c=1; c<=n; c++)
            {
                for (d=1; d<=m; d++)
                {
                    su=s[c][d]-s[a-1][d]-s[c][b-1]+s[a-1][b-1];
                    if (v[c][d]==1)
                        d++;
                    if (su<=y)
                    {
                        e=c-a+1;
                        f=d-b+1;
                        e=e*f;
                        if (e>maxc)
                            maxc=e;
                    }
                }
            }
        }
    }
    fout<<maxc;
    return 0;
}