Pagini recente » Cod sursa (job #286840) | Cod sursa (job #3229214)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
struct Cell {
int row, col, productivity;
Cell(int r, int c, int p) : row(r), col(c), productivity(p) {}
bool operator<(const Cell& other) const {
return productivity < other.productivity;
}
};
int main() {
int N, M;
f >> N >> M;
vector<int> productivity(N * N + 1);
for (int i = 1; i <= N * N; ++i) {
f >> productivity[i];
}
for (int q = 0; q < M; ++q) {
int i, j, k;
f >> i >> j >> k;
priority_queue<Cell> max_heap;
for (int x = i; x < i + k; ++x) {
for (int y = j; y < j + k; ++y) {
int index = (x - 1) * N + y;
max_heap.push(Cell(x, y, productivity[index]));
}
}
int max_productivity = max_heap.top().productivity;
g << max_productivity << "\n";
}
return 0;
}