-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd.cpp
51 lines (46 loc) · 959 Bytes
/
d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
#define fastio ios_base::sync_with_stdio(false)
#define debug(x) cerr << #x << " is " << x << "\n"
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define For(i, n) for(int i=0; i < n; i++)
const int N=1e5+7;
ll arr[N];
void solve(){
int n;
cin >> n;
For(i, n){
cin >> arr[i];
}
sort(arr, arr+n);
ll ans = 0;
ll m = 1e10;
ll l = n/2;
l += (n%2==0 ? 1:2);
for(int i=0; i < l; i++){
if(m > abs(arr[i]-arr[i+n/2-1])){
m = abs(arr[i]-arr[i+n/2-1]);
ans = 0;
for(int j=i; j < (i+(n/2))-1; j++){
ans += abs(arr[j]-arr[j+1]);
}
}
}
cout << ans << endl;
}
int main(){
fastio;
freopen("min.in", "r", stdin);
solve();
return 0;
}