#include <bits/stdc++.h>
#include "wiring.h"
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
long long min_total_length(vector<int> r,vector<int> b) {
int n=r.size(),m=b.size();
ll ans=0;
vector <int> used1(n),used2(m);
for(int i=0;i<n;i++){
used1[i]=1;
ll mn=1e18,pos=-1,mn2=1e18;
for(int j=0;j<m;j++){
if(!used2[j] && abs(r[i]-b[j])<mn){
mn=abs(r[i]-b[j]);
pos=j;
}
mn2=min(mn2,(ll)abs(r[i]-b[j]));
}
if(pos==-1)ans+=mn2;
else{
used2[pos]=1;
ans+=mn;
}
}
for(int i=0;i<m;i++){
if(!used2[i]){
used2[i]=1;
ll mn=1e18,pos=-1,mn2=1e18;
for(int j=0;j<n;j++){
if(!used1[j] && abs(b[i]-r[j])<mn){
mn=abs(b[i]-r[j]);
pos=j;
}
mn2=min(mn2,(ll)abs(b[i]-r[j]));
}
if(pos==-1)ans+=mn2;
else{
used1[pos]=1;
ans+=mn;
}
}
}
return ans;
}
/*signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
vector <int> a(n),b(m);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<m;i++)cin>>b[i];
cout<<min_total_length(a,b);
}*/
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
1018 ms |
2056 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '19704' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '27', found: '32' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |