Submission #147416

#TimeUsernameProblemLanguageResultExecution timeMemory
147416ipaljakSimfonija (COCI19_simfonija)C++14
110 / 110
44 ms3832 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " " << x << endl #define FOR(i, a, b) for (int i = (a); i < int(b); ++i) #define REP(i, n) FOR(i, 0, n) #define _ << " " << typedef long long llint; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 10; const llint INF = 1e18; int n, k; int a[MAXN], b[MAXN], diff[MAXN]; llint pref[MAXN]; llint sum(int l, int r) { if (l == 0) return pref[r]; return pref[r] - pref[l - 1]; } int main(void) { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < n; ++i) scanf("%d", &b[i]); for (int i = 0; i < n; ++i) diff[i] = a[i] - b[i]; sort(diff, diff + n); pref[0] = (llint) diff[0]; for (int i = 1; i < n; ++i) pref[i] = pref[i - 1] + (llint) diff[i]; llint sol = INF; k = n - k; for (int l = 0; l + k - 1 < n; ++l) { int r = l + k - 1; int m = l + (k / 2) - (k % 2 == 0); sol = min(sol, diff[m] * (m - l + 1) - sum(l, m) + sum(m, r) - diff[m] * (r - m + 1)); } printf("%lld\n", sol); return 0; }

Compilation message (stderr)

simfonija.cpp: In function 'int main()':
simfonija.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &k);
   ~~~~~^~~~~~~~~~~~~~~~
simfonija.cpp:28:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
                               ~~~~~^~~~~~~~~~~~~
simfonija.cpp:29:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 0; i < n; ++i) scanf("%d", &b[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...