답안 #147416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147416 2019-08-29T13:35:15 Z ipaljak Simfonija (COCI19_simfonija) C++14
110 / 110
44 ms 3832 KB
#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

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]);
                               ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 2296 KB Output is correct
2 Correct 40 ms 2240 KB Output is correct
3 Correct 38 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2296 KB Output is correct
2 Correct 40 ms 2296 KB Output is correct
3 Correct 38 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 2296 KB Output is correct
2 Correct 39 ms 2296 KB Output is correct
3 Correct 37 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2300 KB Output is correct
2 Correct 37 ms 2316 KB Output is correct
3 Correct 38 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 2284 KB Output is correct
2 Correct 44 ms 3668 KB Output is correct
3 Correct 42 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 2296 KB Output is correct
2 Correct 38 ms 2296 KB Output is correct
3 Correct 42 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 2272 KB Output is correct
2 Correct 39 ms 3704 KB Output is correct
3 Correct 43 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 2296 KB Output is correct
2 Correct 43 ms 3672 KB Output is correct
3 Correct 44 ms 3648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 2268 KB Output is correct
2 Correct 38 ms 3704 KB Output is correct
3 Correct 44 ms 3664 KB Output is correct