Skip to content

Instantly share code, notes, and snippets.

@gbrls
Created May 29, 2020 00:10
Show Gist options
  • Select an option

  • Save gbrls/e0cd19d64a2683a2b4a2732669fd2233 to your computer and use it in GitHub Desktop.

Select an option

Save gbrls/e0cd19d64a2683a2b4a2732669fd2233 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
map<int,int> idToCasa;
for(int i=0;i<n;i++) {
int aux;
cin>>aux;
idToCasa[aux]=i;
}
int pos=0;
int acc=0;
for(int i=0;i<m;i++) {
int id;
cin>>id;
int nPos = idToCasa[id];
acc += abs(pos-nPos);
pos = nPos;
}
cout<<acc<<'\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment