# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
383665 | aris12345678 | 전선 연결 (IOI17_wiring) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}