Submission #103587

# Submission time Handle Problem Language Result Execution time Memory
103587 2019-03-31T19:10:05 Z kishtarn555 Simfonija (COCI19_simfonija) C++14
11 / 110
1000 ms 2724 KB
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<algorithm>

using namespace std;
int N,M, K;
long long a[100000];
long long b[100000];
long long differ[100000];
long long aab(long long x) {
    if (x < 0)return -x;
    return x;
}
long long eval(long long x) {
    int ini=0,fini=N;
    if (x < 0) {
        ini =K;
    } else {
        fini = N-K;
    }
    long long s= 0;

    for (int i = ini; i < fini; i++) {
            if (K!=0) {
                s+=aab(differ[i]+x);
            } else {
                s+=aab((a[i]+x)-b[i]);
            }
    }
    return s;

}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >>N>>K;
    for (int i= 0; i < N; i ++) {
        cin >> a[i];
    }

    for (int i= 0; i < N; i ++) {
        cin >> b[i];
        differ[i]=a[i]-b[i];
    }
//    return 0;
    sort(differ,differ+N);
//    return 0;
long long best=eval(0);
    for (int i = -2e5; i <=2e5; i++) {
        best=min(best,eval(i));
    }
    cout << best;



    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 384 KB Output is correct
2 Correct 16 ms 384 KB Output is correct
3 Correct 19 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 2660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1032 ms 2724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 2688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 2688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 2708 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -