Pagini recente » Cod sursa (job #816735) | Cod sursa (job #2775481) | Cod sursa (job #2866121) | Cod sursa (job #1879895) | Cod sursa (job #3134056)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const string inputFileName = "plantatie.in";
const string outputFileName = "plantatie.out";
int main() {
ifstream inputFile(inputFileName);
if (!inputFile) {
cerr << "Failed to open the input file." << endl;
return 1;
}
ofstream outputFile(outputFileName);
if (!outputFile) {
cerr << "Failed to open the output file." << endl;
return 1;
}
int N, M;
inputFile >> N >> M;
vector<vector<int>> A(N + 1, vector<int>(N + 1));
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= N; ++j) {
inputFile >> A[i][j];
}
}
for (; M > 0; --M) {
int i, j, k;
inputFile >> i >> j >> k;
int maxElement = 0;
for (int x = i; x <= i + k - 1; ++x) {
for (int y = j; y <= j + k - 1; ++y) {
maxElement = max(maxElement, A[x][y]);
}
}
outputFile << maxElement << endl;
}
inputFile.close();
outputFile.close();
return 0;
}