forked from MukulCode/CodingClubIndia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoliceStation.cpp
More file actions
55 lines (44 loc) · 987 Bytes
/
PoliceStation.cpp
File metadata and controls
55 lines (44 loc) · 987 Bytes
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
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function Template for C++
class Solution {
public:
int solve(int N, int a, vector<int> x)
{
sort(x.begin(),x.end());
int k=x.size()-1;
int s=0;
int c=0;
for(int i=k;c<=2;i--)
{
if(x[k]!=x[k-1])
{
s+=(abs(x[k]-a));
c++;
}
else
{
s+=(abs(x[k]-a));
}
}
return s;
// code here
}
};
// { Driver Code Starts.
int main() {
int T;
cin >> T;
while (T--) {
int N, a;
cin >> N >> a;
vector<int> x(N);
for (int i = 0; i < N; i++)
cin >> x[i];
Solution ob;
cout << ob.solve(N, a, x) << "\n";
}
return 0;
}
// } Driver Code Ends