This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> v;
int cost(int x)
{
int r = 0;
for(auto it:v) r+=abs(it-x);
return r;
}
int bs(int s,int f)
{
if(s==f) return cost(s);
int med = (s+f)/2;
int a= cost(med);
int b = cost(med+1);
if(a<b) return bs(s,med);
return bs(med+1,f);
}
main()
{
int n,m;
cin>>n>>m;
v.resize(m);
int ma = 0,mi = 1e9;
for(int i=0;i<m;i++)
{
int a;
cin>>a>>v[i];
ma = max(ma,v[i]);
mi = min(mi,v[i]);
}
cout<<bs(mi,ma)<<endl;
}
Compilation message (stderr)
fireworks.cpp:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# | 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... |