Pagini recente » Cod sursa (job #1707809) | Cod sursa (job #1194852) | Cod sursa (job #1839767) | Cod sursa (job #2958738) | Cod sursa (job #1681221)
#include <iostream>
#include <cstdio>
using namespace std;
int mat[501][501];
int maxim[501][25];
int main()
{
FILE *fin = fopen("plantatie.in", "r");
FILE *fout = fopen("plantatie.out", "w");
int n, t, x, y, lat, rez, col1, col2;
fscanf(fin, "%d%d", &n, &t);
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
fscanf(fin, "%d", &mat[i][j]);
if(mat[i][j] > maxim[i][(j - 1) / 25])
maxim[i][(j - 1) / 25] = mat[i][j];
}
}
while(t--){
fscanf(fin, "%d%d%d", &x, &y, &lat);
rez = 0;
col1 = y;
col2 = y + lat - 1;
for(int i = x; i < x + lat; ++i){
for(int j = col1; j <= col2 && j <= (col1 - 1) / 25 * 25; ++j)
if(mat[i][j] > rez)
rez = mat[i][j];
for(int j = col2; j >= col1 && j > ((col2 - 1) / 25 - 1) * 25; --j)
if(mat[i][j] > rez)
rez = mat[i][j];
for(int j = (col1 - 1) / 25 + 1; j <= (col2 - 1) / 25 - 1; ++j)
if(maxim[i][j] > rez)
rez = maxim[i][j];
}
fprintf(fout, "%d\n", rez);
}
return 0;
}