Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- int n, m;
- scanf("%d%d", &n, &m);
- int mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- scanf("%d", &mat[i][j]);
- }
- }
- int k;
- scanf("%d", &k);
- int V[k];
- for(int i = 0; i < k; i++) {
- int pi, pj;
- scanf("%d%d", &pi, &pj);
- if(pi + 1 < n && pj + 1 < m) {
- int maks = mat[pi][pj];
- if(maks < mat[pi + 1][pj]) {
- maks = mat[pi + 1][pj];
- }
- if(maks < mat[pi][pj + 1]) {
- maks = mat[pi][pj + 1];
- }
- if(maks < mat[pi + 1][pj + 1]) {
- maks = mat[pi + 1][pj + 1];
- }
- V[i] = maks;
- }
- else {
- V[i] = -1;
- }
- }
- for(int i = 0; i < k; i++) {
- printf("%d ", V[i]);
- }
- }
- /*
- 5 5
- 1 7 5 0 4
- 2 3 18 -3 5
- 14 0 7 5 2
- 3 3 4 5 6
- 7 0 0 1 2
- *.*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement