Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

Please spot the error!
Difference between en1 and en2, changed 1,485 character(s)
[problem](https://codeforces.com/contest/1651/problem/C)↵

My solution : 


#include <bits/stdc++.h>↵
using namespace std;↵
#define rep(i,a,b) for (int i = a; i < b; i++)↵
#define ll long long↵
template<typename A>↵
istream& operator>>(istream& fin, vector<A>& v)↵
{↵
    for (auto it = v.begin(); it != v.end(); ++it)↵
        fin >> *it;↵
    return fin;↵
}↵
inline void solve(){↵
    ll n;cin >> n;↵
    vector<ll> a(n),b(n);↵
    cin >> a >> b;↵

    vector<ll> v = {a.front(),b.front(),a.back(),b.back()};↵
    bool done[4] = {0};↵

    ll ans = 0;↵
    rep(i,0,4){↵
        if(done[i]){↵
            continue;↵
        }↵
        if(i & 1){↵
            ll mn = 1e10;↵
            for(auto j : a){↵
                mn = min(mn,abs(j - v[i]));↵
            }↵
            ans += mn;↵
            rep(j,0,4){↵
                if(!done[j] && mn == abs(v[j] - v[i])){↵
                    done[j] = 1;↵
                    break;↵
                }↵
            }↵
        }↵
        else{↵
            ll mn = 1e10;↵
            for(auto j : b){↵
                mn = min(mn,abs(j - v[i]));↵
            }↵
            ans += mn;↵
            rep(j,0,4){↵
                if(!done[j] && mn == abs(v[j] - v[i])){↵
                    done[j] = 1;↵
                    break;↵
                }↵
            }↵
        }↵
        done[i] = 1;↵
    }↵
    cout << ans;↵
}↵
int main()↵
{↵
    ios_base::sync_with_stdio(0);↵
    cin.tie(0);↵
    cout.tie(0);↵
    int t = 1;↵
    cin >> t;↵
    while (t--)↵
    {↵
        solve();↵
        cout<<endl;↵
    }↵
    return 0;↵
}
(https://codeforces.com/contest/1651/submission/271500008)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Whitewiz 2024-07-20 12:39:58 168
en2 English Whitewiz 2024-07-20 12:36:04 1485
en1 English Whitewiz 2024-07-20 12:33:51 1601 Initial revision (published)