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