Cod sursa(job #2056494)

Utilizator alextodoranTodoran Alexandru Raul alextodoran Data 4 noiembrie 2017 12:05:02
Problema Plantatie Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <iostream>
#include <fstream>
#define INF 1000000002
using namespace std;

int n, m, i, j, k, a, b, c, ma[502][502], d[502][502], mx, mxx;

int main()
{
    ifstream fin ("plantatie.in");
    ofstream fout ("plantatie.out");
    fin >> n >> m;
    for(i = 1; i <= n; i++)
    {
        ma[i][0] = INF;
        for(j = 1; j <= n; j++)
        {
            fin >> ma[i][j];
            for(k = j - 1; ma[i][k] < ma[i][j]; k = d[i][k]);
                d[i][j] = k;
        }
    }
    for(k = 1; k <= m; k++)
    {

        fin >> a >> b >>c;
        mxx = 0;
        for(i = a; i <= a + c - 1; i++)
        {
            for(j = b + c - 1; j >= b; j = d[i][j])
                mx = ma[i][j];
            if(mx > mxx)
                mxx = mx;
            //fout << mx << " ";
        }
        //fout << "\n";
        fout << mxx << "\n";
    }
    return 0;
}