Cod sursa(job #3186242)

Utilizator Alexbora13Bora Ioan Alexandru Alexbora13 Data 22 decembrie 2023 12:11:59
Problema Teren Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 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 = 0;
            int sum = 0;
            for(int j=1; j<=n; j++)
            {
                sum+=sp[p][j]-sp[l-1][j];
                while(sum>k && st<=m)
                    sum-=sp[p][st]-sp[l-1][st++];
                armax = max(armax,(p-l+1)*(j-st+1));
            }
        }
    }
    cout << armax;
    return 0;
}