#include <bits/stdc++.h>
using namespace std;
void jh()
{
long long n,m;
cin >>n>>m;
long long arr[n];
for (int i = 0; i < n; ++i)
{
cin >>arr[i];
}
long long min = 1,mx = m;
long long sum = 0;
for (int i = 0; i < n; ++i)
{
sum += max(abs(arr[i] - 1),abs(arr[i] - mx));
}
cout <<sum<<endl;
}
int main() {
int t;
cin>>t;
while(t--){
jh();
}
return 0;
}
JOIN US ON TELEGRAM
Telegram
Youtube
Get Notified Faster
Maximize Colours
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[3], s;
void solve()
{
s = 0;
cin >> a[0] >> a[1] >> a[2];
for (int i = 0; i < 3; ++i)
if (a[i] != 0)
{
a[i]--;
s++;
}
for (int i = 0; i < 3; ++i)
for (int j = i + 1; j < 3; ++j)
if (a[i] > a[j])
swap(a[i], a[j]);
if (a[0] >= 2)
{
cout << s + 3 << endl;
return;
}
if (a[0] == 1)
{
cout << (a[2] >= 2 ? s + 2 : s + 1) << endl;
return;
}
cout << (a[1] == 0 ? s : s + 1) << endl;
}
signed main()
{
int T;
cin >> T;
while (T--)
solve();
}