# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
147416 | ipaljak | Simfonija (COCI19_simfonija) | C++14 | 44 ms | 3832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
typedef long long llint;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 10;
const llint INF = 1e18;
int n, k;
int a[MAXN], b[MAXN], diff[MAXN];
llint pref[MAXN];
llint sum(int l, int r) {
if (l == 0) return pref[r];
return pref[r] - pref[l - 1];
}
int main(void) {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
for (int i = 0; i < n; ++i) diff[i] = a[i] - b[i];
sort(diff, diff + n);
pref[0] = (llint) diff[0];
for (int i = 1; i < n; ++i) pref[i] = pref[i - 1] + (llint) diff[i];
llint sol = INF;
k = n - k;
for (int l = 0; l + k - 1 < n; ++l) {
int r = l + k - 1;
int m = l + (k / 2) - (k % 2 == 0);
sol = min(sol, diff[m] * (m - l + 1) - sum(l, m) + sum(m, r) -
diff[m] * (r - m + 1));
}
printf("%lld\n", sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |