Submission #101726

# Submission time Handle Problem Language Result Execution time Memory
101726 2019-03-19T15:52:35 Z mayhoubsaleh Simfonija (COCI19_simfonija) C++14
44 / 110
97 ms 4216 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

ll n,k;
ll dif[100005];
ll suf[100005],pre[100005];
int main(){
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        cin>>dif[i];
    }
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        dif[i]=x-dif[i];
    }

    sort(dif+1,dif+n+1);

    for(ll i=1;i<=n;i++){
        pre[i]=pre[i-1]+dif[i];
    }
    for(ll i=n;i>=1;i--){
        suf[i]=suf[i+1]+dif[i];
    }
    ll ans=1e18;
    for(ll i=1;i<=n;i++){
        //cout<<dif[i]*(i-1)-pre[i-1]+suf[i+1]-dif[i]*(n-i)<<endl;
        ans=min(ans,dif[i]*(i-1)-pre[i-1]+suf[i+1]-dif[i]*(n-i));
    }
    cout<<ans<<endl;
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 2644 KB Output is correct
2 Correct 88 ms 4072 KB Output is correct
3 Correct 81 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 2684 KB Output is correct
2 Correct 89 ms 4216 KB Output is correct
3 Correct 83 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2724 KB Output is correct
2 Correct 81 ms 4216 KB Output is correct
3 Correct 87 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 79 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 2736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 2716 KB Output isn't correct
2 Halted 0 ms 0 KB -