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