Submission #100326

# Submission time Handle Problem Language Result Execution time Memory
100326 2019-03-10T11:46:10 Z tpoppo Simfonija (COCI19_simfonija) C++14
11 / 110
1000 ms 4148 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
const int MAXN = 1e5 + 10;

int n, k;

int a[MAXN];
int b[MAXN];

int sim(int x){
    vector<int> v;
    for(int i=0;i<n;i++) v.push_back( abs(a[i]-b[i] + x));
    sort(v.begin(),v.end());

    int sm = 0;
    for(int i=0;i<n-k;i++) sm += v[i];

    return sm;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);




    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> a[i];

    for(int i=0;i<n;i++) cin >> b[i];

    int l = -2e6;
    int r = 2e6;

    //for(int i=-20;i<20;i++) cout<<i<<": "<<sim(i)<<endl;

    while(l<r){
        //cout<<l<<" "<<r<<endl;
        int m1 = l + (r-l+2)/3;
        int m2 = r - (r-l+2)/3;

        if(sim(m1) < sim(m2)){
            r = m2;
        }else{
            l = m1;
        }
    }

    int rs = 1e9;
    for(int i=-100;i<100;i++){
        rs = min(rs, sim(l+i));
    }


    cout<<rs<<'\n';



    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 4004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 3892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 3924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 954 ms 4036 KB Output is correct
2 Execution timed out 1059 ms 4148 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 4060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1043 ms 3940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 3996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 3924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 3924 KB Time limit exceeded
2 Halted 0 ms 0 KB -