fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int N;
  5. int arr[17];
  6. int sum[3]={};
  7. int total=0;
  8. bool check=false;
  9.  
  10. void solve(int d){
  11. if(d<0){
  12. if(sum[0]==sum[1] && sum[1]==sum[2]){
  13. check=true;
  14. return;
  15. }
  16. }
  17. for(int i=0;i<3;i++){
  18. if(sum[i]+arr[d]<=total){
  19. sum[i]+=arr[d];
  20. solve(d-1);
  21. sum[i]-=arr[d];
  22. }
  23. }
  24. }
  25.  
  26. int main() {
  27. cin >> N;
  28. for(int i=0;i<N;i++){
  29. cin >> arr[i];
  30. total+=arr[i];
  31. }
  32. if(total%3!=0){
  33. cout << "NO" << '\n';
  34. return 0;
  35. }
  36. total/=3;
  37. sort(arr,arr+N);
  38. solve(N-1);
  39. if(check==true){
  40. cout << "YES" << '\n';
  41. }else{
  42. cout << "NO" << '\n';
  43. }
  44. }
Success #stdin #stdout 0.01s 5320KB
stdin
10
12 53 34 23 29 26 19 10 1 6
stdout
YES