fork download
  1. <?php
  2. $apples = array(
  3. 100,
  4. 100,
  5. 200,
  6. 200,
  7. 200
  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. foreach ($array as $key => $value) {
  18.  
  19. $apples2[$value] = count(array_keys($array, $value));
  20.  
  21.  
  22.  
  23. }
  24.  
  25. $summary_mass = 0;
  26. foreach ($apples2 as $mass => &$count) {
  27. if ($count != 0) {
  28.  
  29. $arg = floor($half / $mass);
  30. if ($arg > $count) {
  31. $arg = $count;
  32. }
  33. $sum = $arg * $mass;
  34. $half -= $sum;
  35. $count -= $arg;
  36. if ($arg != 0) {
  37. $summary_mass += $sum;
  38.  
  39. }
  40.  
  41. }
  42.  
  43.  
  44. }
  45. if ($summary_mass == $half2) {
  46. return "Yes\n";
  47. } else {
  48. return "No\n";
  49. }
  50.  
  51.  
  52. }
  53. echo doApple(4, $apples);
  54.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Yes