Submission #147412

#TimeUsernameProblemLanguageResultExecution timeMemory
147412ipaljakSimfonija (COCI19_simfonija)C++14
44 / 110
44 ms3316 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; int n, k; int a[MAXN], b[MAXN]; 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]); vector<int> v; for (int i = 0; i < n; ++i) v.emplace_back(a[i] - b[i]); sort(v.begin(), v.end()); int med = v[n / 2 - (n % 2 == 0)]; int lo = 0, hi = n - 1; for (int i = 0; i < k; ++i) { if (abs(v[lo] - med) > abs(v[hi] - med)) ++lo; else --hi; } //TRACE(lo _ hi _ med); //for (int x : v) printf("%d ", x); //printf("\n"); llint sol = 0; for (int i = lo; i <= hi; ++i) sol += (llint) abs(v[i] - med); printf("%lld\n", sol); return 0; }

Compilation message (stderr)

simfonija.cpp: In function 'int main()':
simfonija.cpp:19: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:20: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:21: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...