Submission #100236

#TimeUsernameProblemLanguageResultExecution timeMemory
100236FutymyCloneSimfonija (COCI19_simfonija)C++14
44 / 110
430 ms2352 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, a[N], b[N]; long long solve (int x) { vector <int> vec; for (int i = 1; i <= n; i++) vec.push_back(abs(a[i] + x - b[i])); sort(vec.begin(), vec.end(), greater <int>()); long long ans = 0; for (int i = m; i < vec.size(); i++) ans += vec[i]; return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; int l = -5e6, r = 5e6, ans = -1e9; while (l <= r) { int mid = (l + r) / 2; long long lef = solve(mid), rig = solve(mid + 1); if (lef == rig) { ans = mid; break; } if (lef < rig) r = mid - 1; else l = mid + 1; } if (ans < -5e8) ans = l; cout << solve(ans); return 0; }

Compilation message (stderr)

simfonija.cpp: In function 'long long int solve(int)':
simfonija.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = m; i < vec.size(); i++) ans += vec[i];
                     ~~^~~~~~~~~~~~
#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...