| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 61664 | KHUSRAV | Wiring (IOI17_wiring) | C++14 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "grader.h"
using namespace std ;
long long min_total_length(vector<int > r , vector<int> b){
    long long used[100001] , ans = 0 , u1[100001] , u2[100001];
    vector<pair<int , pair<int , int > > > v ;
    for(int i = 0 ; i <= 100000 ; i++)
        u1[i] = u2[i] = 0;
    if(r.size() > b.size())
        swap(r , b);
    for(int i = 0 ; i < r.size() ; i ++){
        for(int j = 0 ; j < b.size() ; j ++){
            v.push_back({abs(r[i] - b[j]) , {i , j}});
            u1[i] ++ ;
            u2[j] ++ ;
            ans = ans + abs(r[i] - b[j]);
        }
    }
    sort(v.begin() , v.end());
    reverse(v.begin() , v.end());
    for(int i = 0 ; i < v.size() ; i++){
        cout << v[i].first<<" "<<v[i].second.first<<" "<<v[i].second.second<<'\n';
    }
    for(int i = 0 ; i < v.size() ; i++){
        if(u1[v[i].second.first] > 1 && u2[v[i].second.second] > 1){
            ans = ans - v[i].first;
            u1[v[i].second.first] --;
            u2[v[i].second.second] --;
        }
        else{
            //cout << r[v[i].second.first] <<" - "<<b[v[i].second.second] <<'\n';
        }
    }
    return ans ;
}
