# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100324 | AKaan37 | Simfonija (COCI19_simfonija) | C++17 | 121 ms | 7416 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//Bismillahirrahmanirrahim
#include <bits/stdc++.h>
using namespace std;
typedef long long int lo;
typedef pair< int,int > PII;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (bas+son)/2
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 3000005;
const lo mod = 1000000007;
lo n,m,cev,b[li],a[li],k,mx=-inf;
string s;
vector<lo> v;
vector<lo> vv;
vector<lo> vec;
map<lo,lo> mpp;
int main(){
//~ freopen("simfonija.in.6a","r",stdin);
scanf("%lld %lld",&n,&m);
FOR{
scanf("%lld",&a[i]);
}
FOR{
scanf("%lld",&b[i]);
mpp[abs(a[i]-b[i])]++;
if(mpp[abs(a[i]-b[i])]==1)
v.pb(abs(a[i]-b[i]));
}
lo say=-1;
for(lo i=0;i<(lo)v.size();i++){
if(mpp[v[i]]>mx){cev=0;cev++;say=v[i];}
if(mpp[v[i]]==mx && say!=v[i]){cev++;}
mx=max(mx,mpp[v[i]]);
}
if(cev==1){
lo tut=0;
FOR{
//~ cout<<mx<<endl;
tut+=abs((a[i]+say)-b[i]);
vec.pb(abs((a[i]+say)-b[i]));
//~ cout<<a[i]<<" "<<b[i]<<endl;
}
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());
//~ cout<<vec[0]<<endl;
//~ cout<<vec[1]<<endl;
//~ cout<<vec[2]<<endl;
for(lo i=0;i<m;i++){tut-=vec[i];}
printf("%lld\n",tut);
return 0;
}
for(lo i=0;i<(lo)v.size();i++){
if(mpp[v[i]]==mx) vv.pb(v[i]);
}
sort(vv.begin(),vv.end());
lo mx1=inf;
vec.clear();
lo sayac=0;
FOR{
//~ cout<<mx<<endl;
sayac+=abs((a[i]+vv[(vv.size()-1)/2])-b[i]);
vec.pb(abs((a[i]+vv[(vv.size()-1)/2])-b[i]));
//~ cout<<a[i]<<" "<<b[i]<<endl;
}
for(lo i=0;i<m;i++){sayac-=vec[i];}
mx1=min(mx1,sayac);
vec.clear();
sayac=0;
FOR{
//~ cout<<mx<<endl;
sayac+=abs((a[i]+vv[(vv.size()-1)/2+1])-b[i]);
vec.pb(abs((a[i]+vv[(vv.size()-1)/2+1])-b[i]));
//~ cout<<a[i]<<" "<<b[i]<<endl;
}
for(lo i=0;i<m;i++){sayac-=vec[i];}
mx1=min(mx1,sayac);
vec.clear();
sayac=0;
FOR{
//~ cout<<mx<<endl;
sayac+=abs((a[i]+vv[(vv.size()-1)/2-1])-b[i]);
vec.pb(abs((a[i]+vv[(vv.size()-1)/2]-1)-b[i]));
//~ cout<<a[i]<<" "<<b[i]<<endl;
}
for(lo i=0;i<m;i++){sayac-=vec[i];}
mx1=min(mx1,sayac);
printf("%lld\n",mx1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |