Created
February 12, 2017 18:31
-
-
Save KhaledElshamy/8cceb61b1ee21fbcc1854262bee8e7fd to your computer and use it in GitHub Desktop.
B. Filya and Homework-Codeforces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// working.cpp by Bill Weinman <http://bw.org/> | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
cin>>n; | |
vector<int>a(n); | |
for(int i=0;i<n;i++) | |
cin>>a[i]; | |
sort(a.begin(),a.end()); | |
vector<int>::iterator length; | |
length=unique(a.begin(),a.end()); | |
a.resize(distance(a.begin(),length)); | |
if(a.size()<3) | |
cout<<"YES"<<endl; | |
else if(a.size()==3) | |
{ | |
if(a[0]+a[2]==2*a[1]) | |
cout<<"YES"<<endl; | |
else | |
cout<<"NO"<<endl; | |
} | |
else | |
cout<<"NO"<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment