fork download
  1. // paiza POH! Vol.1
  2. // result:
  3. // http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/65e48d43b37402535955b30426089dbc
  4. // author: Leonardone @ NEETSDKASU
  5. using System;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. string[] nd = Console.ReadLine().Split(' ');
  12. int n = Int32.Parse(nd[0]);
  13. int d = Int32.Parse(nd[1]);
  14. int[] p = new int[n];
  15. for (int i = 0; i < n; i++) {
  16. p[i] = Int32.Parse(Console.ReadLine());
  17. }
  18. Array.Sort(p);
  19. for (int k = 0; k < d; k++) {
  20. int m = Int32.Parse(Console.ReadLine());
  21. int tmp = 0;
  22. int i = 0;
  23. int j = n - 1;
  24. while (i != j) {
  25. int sum = p[i] + p[j];
  26. if (sum > m) {
  27. j--;
  28. } else {
  29. if (sum > tmp) {
  30. tmp = sum;
  31. if (tmp == m) {
  32. break;
  33. }
  34. }
  35. i++;
  36. }
  37. }
  38. Console.WriteLine(tmp);
  39. }
  40. }
  41. }
Success #stdin #stdout 0.04s 33968KB
stdin
10 6
4500
13300
1100
2200
25100
4000
3000
1000
2000
5000
10000
3000
15000
30000
4000
5600
stdout
9500
3000
14400
29600
4000
5600