답안 #410904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410904 2021-05-23T22:13:21 Z Namnamseo Simfonija (COCI19_simfonija) C++17
44 / 110
470 ms 2152 KB
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;
const int maxn = int(1e5) + 10;
const int inf = int(1e8);
const ll linf = 1ll<<60;

int n, k;

int a[maxn], b[maxn];

ll f(int x) {
	priority_queue<int> pq;
	ll pqs = 0;
	for (int i=1; i<=n; ++i) {
		int d = abs(a[i]+x-b[i]);
		pq.push(d); pqs += d;
		if (int(pq.size()) > n-k) {
			pqs -= pq.top(); pq.pop();
		}
	}

	return pqs;
}

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	for (int i=1; i<=n; ++i) cin >> a[i];
	for (int i=1; i<=n; ++i) cin >> b[i];

	int l = -inf, r = inf;
	while (l+3 < r) {
		int mid = l + (r-l)/2;
		if (f(mid) < f(mid+1)) r = mid+1;
		else l = mid;
	}

	ll ans = linf;
	for (int i=l; i<=r; ++i) ans = min(ans, f(i));
	cout << ans << '\n';

	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 2152 KB Output is correct
2 Correct 149 ms 2000 KB Output is correct
3 Correct 142 ms 2036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 2004 KB Output is correct
2 Correct 150 ms 2028 KB Output is correct
3 Correct 144 ms 2032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 1996 KB Output is correct
2 Correct 150 ms 2056 KB Output is correct
3 Correct 141 ms 1980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 328 ms 1320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 320 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 1100 KB Output is correct
2 Incorrect 334 ms 1880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 470 ms 1556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 402 ms 1592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 307 ms 1864 KB Output isn't correct
2 Halted 0 ms 0 KB -