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 MAX 1010101
#define all(v) v.begin(), v.end()
#define ln '\n'
#define MOD 1000000007
#define INF 210000000000
#define pb push_back
#define abs(x) (((x)>0)?(x):(-(x)))
#define len(x) ((x).second-(x).first)
typedef long long ll;
ll C[MAX];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, M;
cin >> N >> M;
ll i;
ll p;
for (i = 1; i <= M; i++) cin >> p >> C[i];
sort(C + 1, C + M + 1);
ll a = C[(M + 1) / 2];
ll ans = 0;
for (i = 1; i <= M; i++) ans += abs(a - C[i]);
cout << ans << ln;
return 0;
}
# | 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... |