Submission #410879

# Submission time Handle Problem Language Result Execution time Memory
410879 2021-05-23T21:24:59 Z Namnamseo Simfonija (COCI19_simfonija) C++17
44 / 110
38 ms 3224 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 < k)
			kd[i] += d[1+i]-d[1];
		if (0 < i)
			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 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1472 KB Output is correct
2 Correct 30 ms 1488 KB Output is correct
3 Correct 30 ms 1416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1384 KB Output is correct
2 Correct 29 ms 1428 KB Output is correct
3 Correct 27 ms 1472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1468 KB Output is correct
2 Correct 28 ms 1424 KB Output is correct
3 Correct 27 ms 1476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 1476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1852 KB Output is correct
2 Incorrect 28 ms 1480 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 1620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1572 KB Output is correct
2 Incorrect 33 ms 3224 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 1596 KB Output isn't correct
2 Halted 0 ms 0 KB -