fork download
  1. <?php
  2. $apples = array(
  3. 200,
  4. 200,
  5. 100
  6.  
  7.  
  8.  
  9. );
  10. function doApple($n, $array)
  11. {
  12.  
  13. $summary = array_sum($array);
  14. $half = $summary / 2;
  15. $half2 = $half;
  16. $apples2 = array();
  17. $apples2 = array_count_values($array);
  18. $summary_mass = 0;
  19. foreach ($apples2 as $mass => &$count) {
  20. if ($count != 0) {
  21.  
  22. $arg = floor($half / $mass);
  23. $arg = min ($arg, $count);
  24. $half -= $arg * $mass;
  25. $count -= $arg;
  26. $summary_mass += $arg * $mass;
  27.  
  28. }
  29.  
  30.  
  31. }
  32. if ($summary_mass == $half2) {
  33. return "Yes\n";
  34. } else {
  35. return "No\n";
  36. }
  37.  
  38.  
  39. }
  40. echo doApple(3, $apples);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
No