Submission #100335

# Submission time Handle Problem Language Result Execution time Memory
100335 2019-03-10T12:46:28 Z tpoppo Simfonija (COCI19_simfonija) C++14
11 / 110
1000 ms 4964 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 rs = 1e9;
    for(auto el : dx){
        //cout<<el<<": "<<sim(el)<<'\n';
        rs = min(rs,sim(el));
    }

    cout<<rs<<'\n';







    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 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 Execution timed out 1063 ms 3656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 3576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 3696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3704 KB Output is correct
2 Correct 38 ms 3580 KB Output is correct
3 Incorrect 97 ms 4964 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1048 ms 3568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3568 KB Output is correct
2 Incorrect 87 ms 3576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1045 ms 3568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1043 ms 3568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 87 ms 3568 KB Output isn't correct
2 Halted 0 ms 0 KB -