Cod sursa(job #2565342)

Utilizator LivcristiTerebes Liviu Livcristi Data 2 martie 2020 13:44:28
Problema Teren Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
#define NUM 305
int s[NUM][NUM];
int n, m, x, sum, k, sol, st, dr;
using namespace std;
int main()
{
    ifstream f("teren.in");
    ofstream g("teren.out");
    f >> n >> m >> x;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
        {
            f >> k;
            s[i][j] = s[i - 1][j] + k;
        }
    for(int i = 1; i <= n; ++i)
    {
        for(int j = i; j <= n; ++j)
        {
            st = 1;
            sum = 0;
            for(dr = 1; dr <= m; ++dr)
            {
                sum += (s[j][dr] - s[i - 1][dr]);
                while(sum > x)
                {
                    sum -= (s[j][st] - s[i - 1][st]);
                    st++;
                }
                sol = max(sol, (dr - st + 1) * (j - i + 1));
            }
        }
    }
    g << sol;
}