# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102559 | 2019-03-25T23:09:49 Z | Ort | Simfonija (COCI19_simfonija) | C++11 | 56 ms | 780 KB |
#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); ll m = 0, c = 0, nc = 0, l, r; if(k%2) m = k / 2; else m = k / 2 - 1; int mv = a[m]; for(int i=0;i<k;i++) c += abs(a[i]-mv); ll om = mv; sol = min(sol,c); inc++; for(int i=0;i<(n-k);i++) { mv = a[m+inc]; inc++; l = a[i]; r = a[i+k]; nc = c - (abs(om-l)) + (abs(mv-r)); if(k%2==0) nc -= (mv - om); sol = min(sol,nc); c = nc; om = mv; } printf("%d", sol); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 35 ms | 768 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 34 ms | 640 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 34 ms | 640 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 780 KB | Output is correct |
2 | Correct | 30 ms | 768 KB | Output is correct |
3 | Correct | 32 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 52 ms | 752 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 760 KB | Output is correct |
2 | Incorrect | 33 ms | 768 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 41 ms | 752 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 40 ms | 768 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 56 ms | 632 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |