-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2121a.cpp
More file actions
45 lines (43 loc) · 1 KB
/
2121a.cpp
File metadata and controls
45 lines (43 loc) · 1 KB
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
#include <bits/stdc++.h>
using namespace std;
#define NO cout<<"NO\n"
#define YES cout<<"YES\n"
#define F first
#define S second
#define cases int _; cin >> _; while(_--)
typedef long long ll;
typedef unsigned long long uint;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef set<int> si;
void solve() {
int a,b; cin >> a >> b;
int max_current = 0;
int min_current = INT_MAX;
for(int i = 0; i < a; i++) {
int c; cin >> c;
max_current = max(max_current, c);
min_current = min(min_current, c);
}
if(b > max_current) {
cout << b-min_current << '\n';
} else if(b < min_current) {
cout << max_current - b << '\n';
} else {
int dist1 = b-min_current, dist2 = max_current-b;
if(dist1 > dist2) {
dist2*=2;
cout << dist2 + dist1 << '\n';
} else {
dist1*=2;
cout << dist2 + dist1 << '\n';
}
}
return;
}
int main() {
cases {
solve();
}
return 0;
}