Submission #410875

#TimeUsernameProblemLanguageResultExecution timeMemory
410875NamnamseoSimfonija (COCI19_simfonija)C++17
0 / 110
71 ms7560 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; using ll = long long; const int maxn = int(1e5) + 10; const int inf = int(1e8); const ll linf = 1ll<<60; int n, k; int a[maxn], b[maxn]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; if (k == n) { cout << "0\n"; return 0; } for (int i=1; i<=n; ++i) cin >> a[i]; for (int i=1; i<=n; ++i) cin >> b[i]; multiset<int> s; for (int i=1; i<=n; ++i) s.insert(b[i]-a[i]); for(;k--;) { int dl = (*(++s.begin())) - (*s.begin()); int dr = (*(--s.end())) - (*(--(--s.end()))); if (dl > dr) s.erase(s.begin()); else s.erase(--s.end()); } vector<int> v(s.begin(), s.end()); int t = max(0, v[v.size()/2]); ll ans = 0; for (int i=0; i<int(v.size()); ++i) { ans += abs(v[i]-t); } cout << ans << '\n'; 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...