1360C - Similar Pairs - CodeForces Solution


constructive algorithms graph matchings greedy sortings *1100

Please click on ads to support us..

Python Code:

m=int(input())
for t in range(m):
	n=int(input())
	a=list(map(int,input().split()))
	a.sort()
	f=0
	if sum(a)%2==0:
		f=1
	else:
		for i in range(n-1):
			if abs(a[i]-a[i+1])==1:
				f=1
				break
	print("YES" if f==1 else "NO")

C++ Code:

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t, a,b,c;
    
    cin>>t;
    
    while(t--)
    {
        cin>>a;
        
        int n[a];
        int ev=0;
        
        for(int i=0;i<a;i++){
            cin>>n[i];
            
            if(n[i]%2==0)
            {
                ev++;
            }
        }
        
        if(ev%2==0)
            cout<<"YES"<<"\n";
        
        else{
            sort(n,n+a);
        
            int min=0;
        
            for(int i=0;i<(a-1);i++)
            {
                if((n[i+1]-n[i])==1){
                    min=1;
                    break;
                }
            }
            
            if(min==1)
                 cout<<"YES"<<"\n";
            
            else
                cout<<"NO"<<"\n";
        }
    }
}


Comments

Submit
0 Comments
More Questions

133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram
124A - The number of positions