Submission #410880

# Submission time Handle Problem Language Result Execution time Memory
410880 2021-05-23T21:25:56 Z Namnamseo Simfonija (COCI19_simfonija) C++17
44 / 110
33 ms 2196 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
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];
int d[maxn];

int kd[maxn];

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
	if (k == n) { cout << "0\n"; return 0; }
	for (int i=1; i<=n; ++i) cin >> a[i];
	for (int i=1; i<=n; ++i) cin >> b[i];
	for (int i=1; i<=n; ++i) d[i] = b[i]-a[i];
	sort(d+1, d+n+1);

	for (int i=0; i<=k; ++i) {
		if (i+1 <= n)
			kd[i] += d[1+i]-d[1];
		if (k-i >= 0)
			kd[i] += d[k]-d[k-i];
	}

	int km = min_element(kd, kd+k+1)-kd;
	rotate(d+1, d+1+km, d+n+1);
	int v = d[1+(n-k)/2];
	ll ans = 0;
	for (int i=1; i<1+(n-k); ++i) {
		ans += abs(v-d[i]);
	}
	cout << ans << endl;

	return 0;
}
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1388 KB Output is correct
2 Correct 30 ms 1580 KB Output is correct
3 Correct 28 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1484 KB Output is correct
2 Correct 28 ms 1496 KB Output is correct
3 Correct 26 ms 1608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1364 KB Output is correct
2 Correct 28 ms 1432 KB Output is correct
3 Correct 26 ms 1348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1576 KB Output is correct
2 Incorrect 33 ms 2196 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1868 KB Output is correct
2 Incorrect 28 ms 1840 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 1588 KB Output isn't correct
2 Halted 0 ms 0 KB -