Cod sursa(job #3186250)

Utilizator Alexbora13Bora Ioan Alexandru Alexbora13 Data 22 decembrie 2023 12:33:43
Problema Teren Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
#define MAX 305
using namespace std;

ifstream fin("teren.in");
ofstream fout("teren.out");

int n, m, k, armax;
int y, sp[MAX+1][MAX+1];

int main()
{
    fin >> n >> m >> k;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            fin >> y;
            sp[i][j]=sp[i-1][j]+y;
        }
    }
    for(int l=1; l<=n; l++)
    {
        for(int p=l+1; p<=n; p++)
        {
            int st = 1;
            int dr = 1;
            int sum = sp[p][1]-sp[l-1][1];
            while(st<=m && dr<=m)
            {
                if(sum>k)
                    sum-=sp[p][st]-sp[l-1][st++];
                else
                {
                    armax = max(armax,(p-l+1)*(dr-st+1));
                    sum+=sp[p][++dr]-sp[l-1][dr];
                }
            }
        }
    }
    fout << armax;
    return 0;
}