Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- vector<int>v;
- 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];
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- int najmal_sosed = 2e9;
- if(i + 1 < n) {
- najmal_sosed = min(najmal_sosed, mat[i + 1][j]);
- }
- if(i - 1 >= 0) {
- najmal_sosed = min(najmal_sosed, mat[i - 1][j]);
- }
- if(j + 1 < m) {
- najmal_sosed = min(najmal_sosed, mat[i][j + 1]);
- }
- if(j - 1 >= 0) {
- najmal_sosed = min(najmal_sosed, mat[i][j - 1]);
- }
- if(najmal_sosed > mat[i][j]) {
- v.push_back(najmal_sosed - 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