-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1162B.cpp
More file actions
33 lines (31 loc) · 928 Bytes
/
1162B.cpp
File metadata and controls
33 lines (31 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int mat1[n][m];
int mat2[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>mat1[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>mat2[i][j];
}
}
int f=1;
for(int i=0;i<n-1;i++){
for(int j=0;j<m-1;j++){
if(mat1[i][j]>=mat1[i][j+1] || mat1[i][j]>=mat1[i+1][j]){
if(mat2[i][j]<mat1[i+1][j] && mat2[i][j]<mat1[i+1][j] && mat1[i][j]<mat2[i+1][j] && mat1[i][j]<mat2[i+1][j])
swap(mat2[i][j],mat1[i][j]);
else if(mat2[i][j+1]<mat1[i][j] && mat2[i][j]<mat1[i+1][j] && mat1[i][j]<mat2[i+1][j] && mat1[i][j]<mat2[i+1][j])
swap(mat2[i][j],mat1[i][j]);
}
}
}
if(f)
cout<<"Possible\n";
}