Josif_tepe

Untitled

Mar 10th, 2026
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     int n, m;
  10.     cin >> n >> m;
  11.    
  12.     int mat[n][m];
  13.     for(int i = 0; i < n; i++) {
  14.         for(int j = 0; j < m; j++) {
  15.             cin >> mat[i][j];
  16.         }
  17.     }
  18.    
  19.     vector<int> v;
  20.    
  21.     for(int i = 0; i < n; i++) {
  22.         for(int j = 0; j < m; j++) {
  23.             int najmal_element = 2000000000;
  24.            
  25.             if(i + 1 < n) {
  26.                 najmal_element = min(najmal_element, mat[i + 1][j]);
  27.             }
  28.             if(i - 1 >= 0) {
  29.                 najmal_element = min(najmal_element, mat[i - 1][j]);
  30.             }
  31.            
  32.             if(j + 1 < m) {
  33.                 najmal_element = min(najmal_element, mat[i][j + 1]);
  34.             }
  35.             if(j - 1 >= 0) {
  36.                 najmal_element = min(najmal_element, mat[i][j - 1]);
  37.             }
  38.            
  39.             if(mat[i][j] < najmal_element) {
  40.                 v.push_back(najmal_element - mat[i][j]);
  41.             }
  42.            
  43.         }
  44.     }
  45.    
  46.     sort(v.rbegin(), v.rend());
  47.    
  48.     for(int i= 0; i < v.size(); i++) {
  49.         cout << v[i] << " ";
  50.     }
  51.    
  52.    
  53.     return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment