Submission #225072

#TimeUsernameProblemLanguageResultExecution timeMemory
225072VEGAnnSimfonija (COCI19_simfonija)C++14
44 / 110
1096 ms35836 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define MP make_pair #define PB push_back #define ft first #define sd second #define all(x) x.begin(),x.end() using namespace std; typedef long long ll; const ll N = 100100; const ll OO = 1e18; vector<ll> qr, vc; ll n, k, a[N], b[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (ll i = 0; i < n; i++) cin >> a[i]; for (ll j = 0; j < n; j++){ cin >> b[j]; qr.PB(a[j] - b[j]); } ll ans = OO; sort(all(qr)); qr.resize(unique(all(qr)) - qr.begin()); int lbd = 0, rbd = sz(qr) - 1; if (k == 0){ lbd = rbd = n / 2; } for (int cr = lbd; cr <= rbd; cr++){ ll cur = qr[cr]; ll sum = 0; for (int i = 0; i < n; i++) vc.PB(abs(a[i] - cur - b[i])); sort(all(vc)); for (int i = 0; i + k < n; i++) sum += vc[i]; ans = min(ans, sum); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...