Cod sursa(job #2859603)

Utilizator mateitudordmDumitru Matei mateitudordm Data 1 martie 2022 17:19:12
Problema Teren Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <fstream>
#define nmax 300

using namespace std;

int mat[nmax + 1][nmax + 1];

int main()
{
    ifstream cin("teren.in");
    ofstream cout("teren.out");
    int n, m, k, i, j, l, c, st, dr, mij, sol, maxx = 0, act;
    cin >> n >> m >> k;
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
            cin >> mat[i][j], mat[i][j] = mat[i][j] + mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1];
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
            for (c = j; c <= m; c++)
            {
                st = i, dr = n;
                while (st <= dr)
                {
                    mij = (st + dr) / 2;
                    act = mat[mij][c] - mat[i - 1][c] - mat[mij][j - 1] + mat[i - 1][j - 1];
                    if (act <= k)
                        sol = mij, st = mij + 1;
                    else
                        dr = mij - 1;
                }
            }
    cout << maxx;
    return 0;
}