Pagini recente » Cod sursa (job #275188) | Cod sursa (job #1224490) | Cod sursa (job #800583) | Cod sursa (job #1815453) | Cod sursa (job #3283284)
#include <bits/stdc++.h>
#include <thread>
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
void getMax(int a[501][501], int x, int y, int k, int& result) {
int maxim = 0;
for (int i = x; i<x+k; ++i)
for (int j = y; j<y+k; ++j)
maxim = max(maxim, a[i][j]);
result = maxim;
}
int main() {
int n, m;
fin>>n>>m;
int a[501][501];
for (int i = 1; i <=n; ++i)
for (int j = 1; j<=n; ++j)
fin>>a[i][j];
int x, y, k;
vector<thread> threads;
vector<int> results(m);
for (int t = 0; t < m; ++t) {
fin >> x >> y >> k;
threads.push_back(thread(getMax, a, x, y, k, ref(results[t])));
}
for (auto& th : threads) th.join();
for (const int& result : results) fout << result << endl;
return 0;
}