Submission #104595

#TimeUsernameProblemLanguageResultExecution timeMemory
104595HassoonySimfonija (COCI19_simfonija)C++17
66 / 110
53 ms864 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=(1e9+7); const ll inf=(1ll<<61); const int MX=1e5+9; int n,k,a[MX],x,b[MX]; int main(){ cin>>n>>k; for(int i=0;i<n;i++)scanf("%d",&a[i]); for(int i=0;i<n;i++)scanf("%d",&x),a[i]-=x; sort(a,a+n); int p1=0,p2=n-1; ll ans=0; bool ok=0; while(k--){ int mid=(p1+p2)/2; if(abs(a[mid]-a[p1]) > abs(a[p2]-a[mid]))p1++; else if(abs(a[mid]-a[p1]) < abs(a[p2]-a[mid]))p2--; else{ if(k>=1){ p1++;p2--; k--; } else ok=1; } } if(!ok){ int x=a[(p1+p2)/2]; for(int i=p1;i<=p2;i++){ a[i]-=x; ans+=abs(a[i]); } cout<<ans<<endl; } else{ // cout<<p1<<" "<<p2<<endl; ll ans1=0; b[p1]=a[p1]; p1++; int x=a[(p1+p2)/2]; for(int i=p1;i<=p2;i++){ b[i]=a[i]; a[i]-=x; ans1+=abs(a[i]); } p1--;p2--; x=b[(p1+p2)/2]; for(int i=p1;i<=p2;i++){ b[i]-=x; ans+=abs(b[i]); } cout<<min(ans,ans1)<<endl; } }

Compilation message (stderr)

simfonija.cpp: In function 'int main()':
simfonija.cpp:11:30: 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:12:39: 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",&x),a[i]-=x;
                         ~~~~~~~~~~~~~~^~~~~~~~
#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...