Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int main() {
- int t;
- cin >> t;
- while(t--) {
- int n;
- cin >> n;
- vector<int> a(n), b(n);
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- for(int i = 0; i < n; i++) {
- cin >> b[i];
- }
- ll sum = 0;
- for(int i = 0; i + 1 < n; i++) {
- ll m1 = abs(a[i] - a[i + 1]) + abs(b[i] - b[i + 1]);
- ll m2 = abs(a[i + 1] - b[i]) + abs(b[i + 1] - a[i]);
- sum += min(m1, m2);
- }
- cout << sum << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement