Advertisement
Josif_tepe

Untitled

Mar 30th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5.     int n, m;
  6.     scanf("%d%d", &n, &m);
  7.     int mat[n][m];
  8.     for(int i = 0; i < n; i++) {
  9.         for(int j = 0; j < m; j++) {
  10.             scanf("%d", &mat[i][j]);
  11.         }
  12.     }
  13.     int k;
  14.     scanf("%d", &k);
  15.     int V[k];
  16.     for(int i = 0; i < k; i++) {
  17.         int pi, pj;
  18.         scanf("%d%d", &pi, &pj);
  19.        
  20.         if(pi + 1 < n && pj + 1 < m) {
  21.             int maks = mat[pi][pj];
  22.             if(maks < mat[pi + 1][pj]) {
  23.                 maks = mat[pi + 1][pj];
  24.             }
  25.             if(maks < mat[pi][pj + 1]) {
  26.                 maks = mat[pi][pj + 1];
  27.             }
  28.             if(maks < mat[pi + 1][pj + 1]) {
  29.                 maks = mat[pi + 1][pj + 1];
  30.             }
  31.             V[i] = maks;
  32.         }
  33.         else {
  34.             V[i] = -1;
  35.         }
  36.     }
  37.     for(int i = 0; i < k; i++) {
  38.         printf("%d ", V[i]);
  39.     }
  40. }
  41. /*
  42.  5 5
  43.  1 7 5 0 4
  44.  2 3 18 -3 5
  45.  14 0 7 5 2
  46.  3 3 4 5 6
  47.  7 0 0 1 2
  48.  
  49.  *.*/
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement