Cod sursa(job #3229214)

Utilizator anamaria29sSuditu Ana-Maria anamaria29s Data 14 mai 2024 15:30:17
Problema Plantatie Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#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;
}