# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102561 | Ort | Simfonija (COCI19_simfonija) | C++11 | 55 ms | 796 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<iostream>
#include<algorithm>
#define MAX 100020
#define ll long long
using namespace std;
int n, k, x, inc;
ll sol = 100000000000000000;
int a[MAX];
int main() {
scanf("%d%d", &n, &x); k = n - x;
for(int i=0;i<n;i++) scanf("%d", &a[i]);
for(int i=0;i<n;i++) {scanf("%d", &x); a[i]-=x;}
sort(a, a+n);
int m = 0;
ll c = 0, nc = 0;
if(!(k&2)) m = k>>1;
else m = (k>>1) - 1;
int mv = a[m];
for(int i=0;i<k;i++) c += abs(a[i]-mv);
int om = mv;
sol = min(sol,c); inc++;
for(int i=0;i<(n-k);i++) {
mv = a[m+inc]; inc++;
nc = c - (abs(om-a[i])) + (abs(mv-a[i+k]));
if(!(k&2==0)) nc -= (mv - om);
sol = min(sol,nc);
c = nc; om = mv;
}
printf("%lld", 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... |