# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
383664 | aris12345678 | 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 "wiring.h";
#include <bits/stdc++.h>
using namespace std;
#define int64 long long
const int mxN = 1e6+5;
int64 min_total_length(vector<int> r, vector<int> b) {
int i = r.size()-1, j = b.size()-1;
int64 ans = 0;
while(i >= 0 && j >= 0)
ans += (b[j]-r[i]), i--, j--;
while(i >= 0)
ans += (b[0]-r[i]), i--;
while(j >= 0)
ans += (b[j]-r[0]), j--;
return ans;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector<int> r(n), b(m);
for(int i = 0; i < n; i++)
scanf("%d", &r[i]);
for(int i = 0; i < m; i++)
scanf("%d", &b[i]);
int64 ans = min_total_length(r, b);
printf("%lld\n", ans);
return 0;
}