Pagini recente » Cod sursa (job #500360) | Cod sursa (job #392503) | Cod sursa (job #460446) | Cod sursa (job #3127915) | Cod sursa (job #3133434)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
ifstream f("plantatie.in");
int N, M;
f >> N >> M;
vector<vector<int>> productivity(N, vector<int>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
f >> productivity[i][j];
}
}
vector<vector<int>> maxProductivity(N, vector<int>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == 0 && j == 0) {
maxProductivity[i][j] = productivity[i][j];
} else if (i == 0) {
maxProductivity[i][j] = max(maxProductivity[i][j - 1], productivity[i][j]);
} else if (j == 0) {
maxProductivity[i][j] = max(maxProductivity[i - 1][j], productivity[i][j]);
} else {
maxProductivity[i][j] = max(max(maxProductivity[i - 1][j], maxProductivity[i][j - 1]), productivity[i][j]);
}
}
}
ofstream g("plantatie.out");
for (int i = 0; i < M; i++) {
int query_i, query_j, query_k;
f >> query_i >> query_j >> query_k;
int max_productivity = 0;
for (int row = query_i - 1; row < query_i - 1 + query_k; row++) {
for (int col = query_j - 1; col < query_j - 1 + query_k; col++) {
max_productivity = max(max_productivity, productivity[row][col]);
}
}
g << max_productivity << endl;
}
f.close();
g.close();
return 0;
}