fork(1) download
  1. <?php
  2. // paiza POH! Vol.1
  3. // result:
  4. // http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/f942b27b8a91fe3f2e0d47adf9302379
  5. // author: Leonardone @ NEETSDKASU
  6. $p = array_fill(0, 1000000, 0);
  7. $nd = explode(" ",fgets(STDIN));
  8. $n = (int)$nd[0];
  9. $d = (int)$nd[1];
  10. do { ++$p[(int)fgets(STDIN)]; } while (--$n);
  11. $p[9] = $p[0] = 1;
  12. do {
  13. $f = $m = (int)fgets(STDIN);
  14. $tmp = 0;
  15. for (;;) {
  16. --$f;
  17. while (!$p[$f]) --$f;
  18. if (($e = $m - $f) > $f) break;
  19. if ($f == $e) if ($p[$f] == 1) --$e;
  20. while (!$p[$e]) --$e;
  21. if ($e > 9) if (($e += $f) > $tmp) if (($tmp = $e) == $m) break;
  22. }
  23. echo $tmp, PHP_EOL;
  24. } while (--$d);
  25.  
Success #stdin #stdout 0.2s 20520KB
stdin
5 2
4000
3000
1000
2000
5000
10000
3000
stdout
9000
3000