714B - Filya and Homework - CodeForces Solution


implementation sortings *1200

Please click on ads to support us..

Python Code:

number_of_integers = int(input())
array = list(map(int, input().split(' ')))

convert_to_set = list(set(array))
convert_to_set.sort()

if 0 < len(convert_to_set) < 3:
    print('YES')
elif len(convert_to_set) == 3:
    if convert_to_set[1] - convert_to_set[0] == convert_to_set[2] - convert_to_set[1]:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

C++ Code:

#include <bits/stdc++.h>
#define loop(n) for(int i = 1; i <= n; i++)
#define rloop(n) for(int i = n; i >= 1; i--)
#define loop0(n) for(int i = 0; i < n; i++)
#define rloop0(n) for(int i = n-1; i >= 0; i--)
#define iloop(s,n,step) for(int i = s; i <= n; i+=step)
#define jloop(s,n,step) for(int j = s; j <= n; j+=step)
#define loopit(x) for(auto it = x.begin(); it!= x.end(); it++)
#define all(x) x.begin(),x.end()
using namespace std;
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
int main()
{
    fast();
    int tc = 1;
    //cin >> tc;
    while(tc--){
        long long n,x;
        cin >> n;
        vector<long long> v;
        set<long long> s;
        loop(n){
            cin >> x;
            if(s.find(x)==s.end()){
                v.push_back(x);
                s.insert(x);
            }
        }
        if(v.size()>3){
            cout << "NO";
        }
        else if(v.size()==1 || v.size()==2){
            cout << "YES";
        }
        else if(v.size()==3){
            sort(all(v));
            x=v[0]+v[2];
            if(2*v[1]==x){
                cout << "YES";
            }
            else{
                cout << "NO";
            }
        }
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme
1195A - Drinks Choosing
5D - Follow Traffic Rules
1272A - Three Friends
1632D - New Year Concert
1400D - Zigzags
716C - Plus and Square Root
412A - Poster
844B - Rectangles
1591A - Life of a Flower
1398C - Good Subarrays
629A - Far Relative’s Birthday Cake
1166A - Silent Classroom
1000B - Light It Up
218B - Airport
1463B - Find The Array
1538C - Number of Pairs
621B - Wet Shark and Bishops
476B - Dreamoon and WiFi
152C - Pocket Book
1681D - Required Length
1725D - Deducing Sortability
1501A - Alexey and Train
721B - Passwords
1263D - Secret Passwords