Submission #410881

# Submission time Handle Problem Language Result Execution time Memory
410881 2021-05-23T21:27:28 Z Namnamseo Simfonija (COCI19_simfonija) C++17
55 / 110
34 ms 3140 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 (n-(k-i) >= 1)
			kd[i] += d[n]-d[n-(k-i)];
	}

	int km = max_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 32 ms 1400 KB Output is correct
2 Correct 28 ms 1472 KB Output is correct
3 Correct 32 ms 1480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1472 KB Output is correct
2 Correct 29 ms 1392 KB Output is correct
3 Correct 27 ms 1420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1488 KB Output is correct
2 Correct 29 ms 1460 KB Output is correct
3 Correct 31 ms 1440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1668 KB Output is correct
2 Correct 28 ms 3140 KB Output is correct
3 Correct 29 ms 3136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1732 KB Output is correct
2 Incorrect 31 ms 1660 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 1648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 1524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 1572 KB Output isn't correct
2 Halted 0 ms 0 KB -