include iostream include vector using namespace std int vector int boo

 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
#include<iostream>
#include<vector>
using namespace std;
int n, a = 0, b = 0, c = 0;
vector<int> v;
bool Sum(int k)
{
b += ((v[k] + 1) * (v[k] + 1)) - (v[k] * v[k]);
c += ((v[k] - 1) * (v[k] - 1)) - (v[k] * v[k]);
return ((a + 1) * (a + 1) == b || (a - 1) * (a - 1) == c);
}
int main()
{
cin >> n;
v.resize(n);
for (int i = 0; i < n; ++i)
{
cin >> v[i];
a += v[i];
b += v[i] * v[i];
}
c = b;
for (int i = 0; i < n; ++i)
if (Sum(i))
{
cout << "YES" << endl;
return 0;
}
cout << "NO" << endl;
return 0;
}