#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[1001],b[1001],g1,g2,mx,k;
vector<ll>v,res;
bool f(ll c,ll nacinji)
{
if (nacinji==n) return true;
for (ll i=0;i<n;i++)
{
b[i]=a[i];
}
b[nacinji]=c;
sort(b,b+n);
ll gr1=0,gr2=0;
for (ll i=n-1;i>=0;i--)
{
if (gr1>=gr2) gr2+=b[i];
else gr1+=b[i];
}
if (gr1!=gr2) return false;
else return f(c,nacinji+1);
}
int main()
{
// freopen ("in.txt","r",stdin);
// freopen ("out.txt","w",stdout);
cin >> n;
ll mn=INT_MAX;
for (ll i=0;i<n;i++)
{
cin >> a[i];
mx+=a[i];
if (a[i]<mn) mn=a[i];
}
sort(a,a+n);
for (ll i=n-1;i>=0;i--)
{
if (g1>=g2) g2+=a[i];
else g1+=a[i];
}
if (g1!=g2)
{
cout << 0;
return 0;
}
else
{
for (ll i=0;i<n;i++) b[i]=a[i];
for (ll i=mn;i<=mx;i++)
{
g1=0;
g2=0;
for (ll j=0;j<n;j++)if (b[j]==i-1){b[j]=i;break;}
sort(b,b+n);
for (ll j=n-1;j>=0;j--)
{
if (g1>=g2) g2+=b[j];
else g1+=b[j];
}
if (g1==g2) v.push_back(i);
}
}
for (ll i=0;i<v.size();i++)
{
if (f(v[i],0)==false)v[i]=0;
else k++;
}
cout << k << "\n";
for (ll i=0;i<v.size();i++)
{
if (v[i]!=0) cout << v[i] << " ";
}
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:65:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i=0;i<v.size();i++)
~^~~~~~~~~
bootfall.cpp:71:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i=0;i<v.size();i++)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |