Cod sursa(job #3186245)

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

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

int main()
{
    ifstream cin("teren.in");
    ofstream cout("teren.out");
    cin >> n >> m >> k;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin >> y;
            sp[i][j]=sp[i-1][j]+y;
        }
    }
    for(int l=1; l<=n; l++)
    {
        for(int p=l; 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));
                    dr++;k+=sp[p][dr]-sp[l-1][dr];
                }
            }
        }
    }
    cout << armax;
    return 0;
}