Submission #106265

#TimeUsernameProblemLanguageResultExecution timeMemory
106265hamzqq9Simfonija (COCI19_simfonija)C++14
110 / 110
69 ms3832 KiB
#include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define umax(x,y) x=max(x,y) #define umin(x,y) x=min(x,y) #define ll long long #define ii pair<int,int> #define iii pair<ii,int> #define iiii pair<ii,ii> #define sz(x) ((int) x.size()) #define orta ((bas+son)/2) #define all(x) x.begin(),x.end() #define pw(x) (1<<(x)) #define inf 100000009 #define MOD 998244353 #define N 100005 #define M 2500005 #define LOG 20 #define KOK 300 #define EPS 0.0000001 using namespace std; int n,k; int mn=inf,mx=-inf; int a[N],b[N],ar[N]; ll pre[N]; ll get(int l,int r,int lastng,int cur) { umax(lastng,l); umin(lastng,n-r); ll pos=pre[n-r]-pre[lastng]+(ll)(n-r-lastng)*cur; ll neg=pre[lastng]-pre[l]+(ll)(lastng-l)*cur; return pos-neg; } int main() { 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]); umin(mn,b[i]-a[i]); umax(mx,b[i]-a[i]); } for(int i=1;i<=n;i++) { ar[i]=a[i]-b[i]; } sort(ar+1,ar+1+n); for(int i=1;i<=n;i++) pre[i]=pre[i-1]+ar[i]; int l=k,r=0,lastng=n; ll ans=(ll)inf*inf; for(int i=mn;i<=mx;i++) { while(lastng && ar[lastng]+i>=0) lastng--; while(l && abs(ar[l]+i)<abs(ar[n-r]+i)) l--,r++; umin(ans,get(l,r,lastng,i)); } printf("%lld",ans); }

Compilation message (stderr)

simfonija.cpp: In function 'int main()':
simfonija.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
simfonija.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
simfonija.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&b[i]);
   ~~~~~^~~~~~~~~~~~
#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...