Submission #200100

#TimeUsernameProblemLanguageResultExecution timeMemory
200100SaboonSimfonija (COCI19_simfonija)C++14
110 / 110
43 ms3448 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int maxn = 1e5 + 10; ll par[maxn], a[maxn]; ll cost(int l, int r){ int median = (l + r) >> 1; return a[median] * (median - l + 1) - (par[median] - par[l - 1]) + (par[r] - par[median]) - a[median] * (r - median); } int main(){ ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; k = n - k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++){ int x; cin >> x; a[i] -= x; } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) par[i] = par[i - 1] + a[i]; ll answer = 1000ll * 1000 * 1000 * 1000; for (int l = 1; l <= n - k + 1; l++){ int r = l + k - 1; answer = min(answer, cost(l, r)); } cout << answer << endl; }
#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...