-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholliePS-32.cpp
48 lines (48 loc) · 974 Bytes
/
olliePS-32.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll t;
cin>>t;
for(ll i = 1 ; i<=t ; i++)
{
ll n;
cin>>n;
vector<ll>v;
for(int i = 0 ; i<n ; i++)
{
ll x;
cin>>x;
v.push_back(x);
}
sort(v.begin() , v.end());
int start = 0 , end = n-2;
if(v[start] == v[n-1])
{
cout<<0<<endl;
}
else
{
int count = 0;
while(end>=start)
{
if(v[end] == v[n-1])
{
end--;
continue;
}
else
{
for(int j = start ; j<=end ; j++)
{
v[j]++;
}
count++;
}
}
cout<<count<<endl;
}
}
return 0;
}