fork(1) download
  1. #!/usr/bin/perl
  2. # paiza POH! Vol.1
  3. # result:
  4. # http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/ffa7a20db886bcb77dafa63c1f23c8ef
  5. # author: Leonardone @ NEETSDKASU
  6. @nd = split(/ /,<STDIN>);
  7. $n = int($nd[0]);
  8. $d = int($nd[1]);
  9. @p;
  10. for ($i = 0; $i < $n; $i++) {
  11. $p[$i] = int(<STDIN>);
  12. }
  13. @p = sort {$a <=> $b} @p;
  14. $ci = ($n - 1) >> 1;
  15. $cp = $p[$ci];
  16. for ($i = 0; $i < $d; $i++) {
  17. $m = int(<STDIN>);
  18. if ($m < $cp) {
  19. $f = $ci;
  20. } else {
  21. $f = $n - 1;
  22. }
  23. if ($m - $p[$f] > $cp) {
  24. $e = $ci;
  25. } else {
  26. $e = 0;
  27. }
  28. $tmp = 0;
  29. while ($f != $e) {
  30. $sum = $p[$f] + $p[$e];
  31. if ($sum > $m) {
  32. $f = $f - 1;
  33. } else {
  34. if ($sum > $tmp) {
  35. $tmp = $sum;
  36. }
  37. $e = $e + 1;
  38. }
  39. }
  40. print $tmp, "\n";
  41. }
  42.  
Success #stdin #stdout 0s 3564KB
stdin
5 2
4000
3000
1000
2000
5000
10000
3000
stdout
9000
3000