Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- short n, m;
- int citit;
- map<int, pair<int, int>>mp;
- int main()
- {
- ifstream cin("traseu.in");
- ofstream cout("traseu.out");
- cin>>n>>m;
- for(short i = 1; i<=n; i++){
- for(int j = 1; j<=m; j++){
- cin>>citit;
- mp[citit] = {i, j};
- }
- }
- int maxim = 0;
- for(int i = 1; i<=n*m-1; i++){
- for(int j = i+1; j<=n*m; j++){
- if(mp[j].first >= mp[i].first && mp[j].second>=mp[i].second){
- maxim = max(maxim, abs(mp[j].first - mp[i].first) + abs(mp[j].second-mp[i].second)+1);
- }
- }
- }
- cout<<maxim;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement