Cod sursa(job #1636461)

Utilizator tanasaradutanasaradu tanasaradu Data 7 martie 2016 10:12:01
Problema Teren Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("teren.in");
ofstream fout("teren.out");
int n,m,b[303][303],x,v[303];
void Citire()
{
    int i,j,w;
    fin>>n>>m>>x;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            fin>>w;
            b[i][j]=b[i-1][j]+w;
        }
    fin.close();
}
void Rezolva()
{
    int L1,L2,i,Amax,s,lgmax,j;
    Amax=0;
    for(L1=1;L1<=n;L1++)
       for(L2=L1;L2<=n;L2++)
    {
        for(i=1;i<=m;i++)
        v[i]=b[L2][i]-b[L1-1][i];
        lgmax=0;
        i=1;
        s=0;
        for(j=1;j<=m;j++)
        {
            s+=v[j];
            while(s>x)
            {
                s-=v[i];
                i++;
            }
            lgmax=max(lgmax,j-i+1);
        }
    }
    Amax=max(Amax,lgmax*(L2-L1+1));
    fout<<Amax<<"\n";
}
int main()
{
    Citire();
    Rezolva();
    return 0;
}