Submission #554752

#TimeUsernameProblemLanguageResultExecution timeMemory
554752A_DSimfonija (COCI19_simfonija)C++14
110 / 110
29 ms3300 KiB
#include <bits/stdc++.h> #define int long long #define ii pair<int,int> #define F first #define S second using namespace std; const int N=1e5+100; int a[N]; int pre[N]; void solve() { int n,k; cin>>n>>k; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ int b; cin>>b; a[i]-=b; } sort(a+1,a+n+1); for(int i=2;i<=n;i++){ a[i]-=a[1]; } a[1]=0; for(int i=1;i<=n;i++){ pre[i]=pre[i-1]+a[i]; } int l=k+1,r=n; int ans=1e18; /* for(int i=1;i<=n;i++){ cout<<a[i]<<" "; } cout<<"\n"; */ while(l>=1){ int mid=(l+r)/2; int v=(a[mid]*(mid-l+1)-(pre[mid]-pre[l-1]))+((pre[r]-pre[mid])-(a[mid]*(r-mid))); ans=min(ans,v); // cout<<l<<" "<<r<<" "<<v<<"\n"; l--; r--; } cout<<ans<<"\n"; } main() { ///* ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //*/ int t=1; // cin>>t; while(t--){ solve(); } } /* 7 7 2 5 4 7 4 2 */

Compilation message (stderr)

simfonija.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main()
      | ^~~~
#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...