Submission #990549

#TimeUsernameProblemLanguageResultExecution timeMemory
990549LOLOLOSimfonija (COCI19_simfonija)C++17
44 / 110
498 ms6196 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (ll)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 2e5 + 10; ll a[N], b[N]; ll cost(int n, int k, ll add) { vector <ll> c; for (int i = 1; i <= n; i++) { c.pb(b[i] + add); } ll ans = 0; sort(all(c), [&] (ll a, ll b) {return abs(a) < abs(b);}); for (int i = 0; i < n - k; i++) ans += abs(c[i]); return ans; } ll solve() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { cin >> b[i]; b[i] = a[i] - b[i]; } ll l = -1e9, r = 1e9, m = 0, ans = 1e18; while (l <= r) { m = (l + r) / 2; ll L = cost(n, k, m), R = cost(n, k, m + 1); if (L > R) { l = m + 1; } else { r = m - 1; } ans = min(ans, min(L, R)); } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { cout << solve() << '\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...