fork(2) download
  1. /* paiza POH! Vol.1
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/9c8b072038c3bc1f31b033ac8a906f38
  4.  * author: Leonardone @ NEETSDKASU
  5.  */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #define PMAX (1000000)
  9. #define PC(c) putchar(c)
  10. #define PD(d) printf("%d\n", d)
  11. #define PS(s) printf("%s\n", s)
  12. #define SUMCHECK(tmp, sum, i, u, m) \
  13.   sum = i + u; \
  14.   if (sum > tmp) { \
  15.   tmp = sum; \
  16.   if (tmp == m) break; \
  17.   }
  18.  
  19. int list[PMAX + 1] = {0};
  20.  
  21. inline int gc(void) {
  22. register int c, n = 0;
  23. do {
  24. c = getchar();
  25. } while ((c < '0') || (c > '9'));
  26. do {
  27. n = n * 10 + (c - '0');
  28. c = getchar();
  29. } while ((c >= '0') && (c <= '9'));
  30. return n;
  31. }
  32.  
  33. void pi(register int n) {
  34. register int t;
  35. if (n < 10) {
  36. PC(n + '0');
  37. } else {
  38. t = n / 10;
  39. pi(t);
  40. PC(n - t * 10 + '0');
  41. }
  42. }
  43.  
  44. int main(void) {
  45. register int j, i, u, sum, tmp;
  46. int n, d, m, p, lm;
  47.  
  48. n = gc();
  49. d = gc();
  50.  
  51. j = n + 1;
  52. while (--j) {
  53. ++list[gc()];
  54. }
  55.  
  56. ++list[PMAX];
  57. ++list[9];
  58. j = d + 1;
  59. while (--j) {
  60. i = (m = gc()) - 1;
  61. u = 10;
  62. tmp = 0;
  63. while(!list[i]) --i;
  64. if (i > 9) {
  65. lm = m >> 1;
  66. do {
  67. if ((u = m - i) > i) break;
  68. if (u > 9) {
  69. if (i == u) {
  70. if (list[i] > 1) {
  71. SUMCHECK(tmp, sum, i, u, m);
  72. } else {
  73. --u;
  74. while (!list[u]) --u;
  75. if (u > 9) {
  76. SUMCHECK(tmp, sum, i, u, m);
  77. }
  78. }
  79. } else {
  80. while (!list[u]) --u;
  81. if (u > 9) {
  82. SUMCHECK(tmp, sum, i, u, m);
  83. }
  84. }
  85. }
  86. --i;
  87. while (!list[i]) --i;
  88. } while (i >= lm);
  89. }
  90. pi(tmp);
  91. PC('\n');
  92. }
  93.  
  94. return 0;
  95. }
  96.  
Success #stdin #stdout 0s 6156KB
stdin
    5 2
    4000
    3000
    1000
    2000
    5000
    10000
    3000
stdout
9000
3000