# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
314102 | 2020-10-18T11:00:11 Z | phathnv | Simfonija (COCI19_simfonija) | C++11 | 43 ms | 3448 KB |
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "SIMFONIJA" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 1e5 + 1; int n, k, a[N], b[N]; ll s[N]; void readInput(){ scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i <= n; i++) scanf("%d", &b[i]); } void solve(){ if (n == k){ printf("0"); return; } for(int i = 1; i <= n; i++) a[i] -= b[i]; sort(a + 1, a + 1 + n); for(int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i]; ll res = 1e18; for(int i = 0; i <= k; i++){ int l = i + 1; int r = n - (k - i); int mid = (l + r) >> 1; res = min(res, (ll) a[mid] * (mid - l + 1) - (s[mid] - s[l - 1]) + (s[r] - s[mid]) - (ll) a[mid] * (r - mid)); } cout << res; } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } readInput(); solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 1912 KB | Output is correct |
2 | Correct | 37 ms | 3320 KB | Output is correct |
3 | Correct | 35 ms | 3320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 1912 KB | Output is correct |
2 | Correct | 37 ms | 3328 KB | Output is correct |
3 | Correct | 38 ms | 3320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 1912 KB | Output is correct |
2 | Correct | 37 ms | 3280 KB | Output is correct |
3 | Correct | 36 ms | 3320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 1912 KB | Output is correct |
2 | Correct | 38 ms | 1920 KB | Output is correct |
3 | Correct | 36 ms | 1912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 1912 KB | Output is correct |
2 | Correct | 42 ms | 3320 KB | Output is correct |
3 | Correct | 40 ms | 3320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 1912 KB | Output is correct |
2 | Correct | 35 ms | 1912 KB | Output is correct |
3 | Correct | 39 ms | 3320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 1912 KB | Output is correct |
2 | Correct | 36 ms | 3320 KB | Output is correct |
3 | Correct | 40 ms | 3320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 1912 KB | Output is correct |
2 | Correct | 41 ms | 3324 KB | Output is correct |
3 | Correct | 42 ms | 3320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 1912 KB | Output is correct |
2 | Correct | 37 ms | 3320 KB | Output is correct |
3 | Correct | 40 ms | 3448 KB | Output is correct |