Skip to content

Commit 692e31b

Browse files
committed
Added 1399A - Remove Smallest.cpp
1 parent 376730c commit 692e31b

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

1399A - Remove Smallest.cpp

+42-28
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
1+
// ॐ नमः शिवाय
12
#include<bits/stdc++.h>
23
using namespace std;
34

4-
//Code Written By: Vikash Patel
5+
#define ll long long
6+
#define pb push_back
7+
#define ff first
8+
#define ss second
9+
#define mp make_pair
10+
11+
// Code Written By: Vikash Patel
12+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
513

6-
#define ll long long
7-
#define ull unsigned long long
8-
#define pb push_back
9-
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
14+
string solve(int a[], int n)
15+
{
16+
if(n == 1)
17+
return "YES";
18+
sort(a, a+n);
19+
int maxi = INT_MIN;
20+
for(int i=1; i<n; i++)
21+
{
22+
maxi = max(maxi, a[i]-a[i-1]);
23+
}
24+
if(maxi > 1)
25+
return "NO";
26+
return "YES";
27+
}
1028

1129
int main()
1230
{
13-
fastread();
14-
int t,n,a[55];
31+
ios_base::sync_with_stdio(0);
32+
cin.tie(0);
33+
cout.tie(0);
34+
35+
// #ifndef ONLINE_JUDGE
36+
// freopen("input.txt", "r", stdin);
37+
// freopen("/Users/vikash/Desktop/output.txt", "w", stdout);
38+
// #endif
39+
40+
int t;
1541
cin>>t;
16-
while(t--){
42+
while(t--)
43+
{
44+
int n;
1745
cin>>n;
18-
for(int i=0; i<n; i++){
46+
int a[n];
47+
for(int i=0; i<n; i++)
48+
{
1949
cin>>a[i];
2050
}
21-
if(n == 1){
22-
cout<<"YES"<<endl;
23-
continue;
24-
}
25-
sort(a,a+n);
26-
vector<int>v;
27-
int dif = 0;
28-
for(int i=1; i<n; i++){
29-
dif = abs(a[i] - a[i-1]);
30-
v.push_back(dif);
31-
}
32-
sort(v.begin(), v.end(), greater<int>());
33-
if(v[0] > 1){
34-
cout<<"NO"<<endl;
35-
}
36-
else{
37-
cout<<"YES"<<endl;
38-
}
51+
cout<<solve(a, n)<<endl;
3952
}
40-
}
53+
return 0;
54+
}

0 commit comments

Comments
 (0)