Submission #100336

# Submission time Handle Problem Language Result Execution time Memory
100336 2019-03-10T12:49:08 Z tpoppo Simfonija (COCI19_simfonija) C++14
55 / 110
81 ms 5048 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;
    v.reserve(n);
    for(int i=0;i<n;i++) v.push_back( abs(a[i]-b[i] + x));

    nth_element(v.begin(),v.begin() + n - k,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];


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

    dx.erase(unique(dx.begin(),dx.end()),dx.end());



    int l = 0;
    int r = dx.size()+1;
    while(l<r){
        //cout<<l<<" "<<r<<endl;
        int m1 = l + (r-l)/2;

        if(sim(dx[m1]) < sim(dx[m1 + 1])){
            r = m1;
        }else{
            l = m1 + 1;
        }
    }

    cout<<sim(dx[l])<<'\n';







    return 0;
}
# 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 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 3568 KB Output is correct
2 Correct 59 ms 5048 KB Output is correct
3 Correct 38 ms 4976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3640 KB Output is correct
2 Correct 39 ms 4976 KB Output is correct
3 Correct 39 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 3576 KB Output is correct
2 Correct 43 ms 4976 KB Output is correct
3 Correct 35 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 3576 KB Output is correct
2 Correct 37 ms 3576 KB Output is correct
3 Correct 45 ms 3568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 3568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 3620 KB Output is correct
2 Incorrect 45 ms 3620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 3568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 3640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 3568 KB Output isn't correct
2 Halted 0 ms 0 KB -