DIVIDING - Link.
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long summation = ((n*(n+1))/2);
long long s = 0;
for (int i = 0; i < n; ++i)
{
int num;
cin >> num;
s += num;
}
if (s == summation)
cout << "YES\n";
else
cout << "NO\n";
}
I got WA because of possible overflow. That’s why I assigned summation
to long long
. Now I’m still getting WA. What did I do wrong?