Cod sursa(job #996732)

Utilizator mitrutstrutMitrea Andrei Ionut mitrutstrut Data 12 septembrie 2013 15:57:28
Problema Teren Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
 
using namespace std;
 
int n,m,X,ariemax;
short a[301][301],s[301][301],v[301];
 
inline void Read()
{
    int i,j;
    ifstream fin("teren.in");
    fin>>n>>m>>X;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            fin>>a[i][j];
    fin.close();
}
 
inline void Solve()
{
    ofstream fout("teren.out");
    int i,j,i1,i2,suma,st,dr;
    for(j=1;j<=m;j++)
        for(i=1;i<=n;i++)
            s[i][j]=s[i-1][j]+a[i][j];
    for(i1=1;i1<=n;i1++)
        for(i2=i1;i2<=n;i2++)
        {
            for(j=1;j<=m;j++)
                v[j]=s[i2][j]-s[i1-1][j];
            st=1;suma=0;
            for(dr=1;dr<=m;dr++)
            {
                suma+=v[dr];
                while(st<=dr && suma>X)
                {
                    suma-=v[st];
                    st++;
                }
                if(st<=dr)
                    ariemax=max(ariemax, (i2-i1+1)*(dr-st+1));
            }
        }
    fout<<ariemax<<"\n";
    fout.close();
}
 
int main()
{
    Read();
    Solve();
    return 0;
}