Submission #636991

#TimeUsernameProblemLanguageResultExecution timeMemory
636991ieeSimfonija (COCI19_simfonija)C++17
110 / 110
20 ms3680 KiB
// iee #include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define per(i, a, b) for (int i = (a); i >= (b); --i) #define fi first #define se second using ll = long long; using ull = unsigned long long; using namespace std; void work(int); template <class T> void read(T &x) { x = 0; int f = 1, ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch - '0'); ch = getchar(); } x *= f; } int main() { int TT = 1; // cin >> TT; rep(CAS, 1, TT) work(CAS); return 0; } const int N = 1e5 + 5; int n, k, a[N], b[N], d[N]; ll s[N]; ll calc(int l, int r) { int mid = l + (r - l + 1 + 1) / 2 - 1; return (ll) d[mid] * (mid - (l - 1)) - (s[mid] - s[l - 1]) + (s[r] - s[mid]) - (ll) d[mid] * (r - mid); } void work(int CASE) { read(n), read(k); k = n - k; rep(i, 1, n) read(a[i]); rep(i, 1, n) read(b[i]), d[i] = a[i] - b[i]; sort(d + 1, d + n + 1); rep(i, 1, n) s[i] = s[i - 1] + d[i]; ll mn = 1e18; rep(l, 1, n - k + 1) mn = min(mn, calc(l, l + k - 1)); printf("%lld", mn); }
#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...