제출 #314102

#제출 시각아이디문제언어결과실행 시간메모리
314102phathnvSimfonija (COCI19_simfonija)C++11
110 / 110
43 ms3448 KiB
#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; }

컴파일 시 표준 에러 (stderr) 메시지

simfonija.cpp: In function 'void readInput()':
simfonija.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
simfonija.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
simfonija.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
simfonija.cpp: In function 'int main()':
simfonija.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   49 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
simfonija.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   50 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...