Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main() {
- int n, m;
- cin >> n >> m;
- int mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> mat[i][j];
- }
- }
- vector<int> v;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- int najmal_element = 2000000000;
- if(i + 1 < n) { // dolniot sosed
- najmal_element = min(najmal_element, mat[i + 1][j]);
- }
- if(i - 1 >= 0) { // gorniot sosed
- najmal_element = min(najmal_element, mat[i - 1][j]);
- }
- if(j + 1 < m) { // desniot sosed
- najmal_element = min(najmal_element, mat[i][j + 1]);
- }
- if(j - 1 >= 0) { // leviot sosed
- najmal_element = min(najmal_element, mat[i][j - 1]);
- }
- if(najmal_element > mat[i][j]) {
- v.push_back(najmal_element - mat[i][j]);
- }
- }
- }
- if(v.size() == 0) {
- cout << -1 << endl;
- }
- else {
- sort(v.begin(), v.end());
- for(int i = v.size() - 1; i >= 0; i--) {
- cout << v[i] << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement