fork(2) download
  1. /* paiza POH! Vol.1
  2.  * result:
  3.  * http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/eaff529ae4d6a00ebf3f808dbe80ab31
  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;
  49.  
  50. n = gc();
  51. d = gc();
  52.  
  53. j = n + 1;
  54. while (--j) {
  55. ++list[gc()];
  56. }
  57.  
  58. ++list[9];
  59. j = d + 1;
  60. while (--j) {
  61. i = m = gc();
  62. tmp = 0;
  63. do {
  64. --i;
  65. while(!list[i]) --i;
  66. if ((u = m - i) > i) break;
  67. if (u > 9) {
  68. if (i == u) {
  69. if (list[i] > 1) {
  70. SUMCHECK(tmp, sum, i, u, m);
  71. } else {
  72. --u;
  73. while (!list[u]) --u;
  74. if (u > 9) {
  75. SUMCHECK(tmp, sum, i, u, m);
  76. }
  77. }
  78. } else {
  79. while (!list[u]) --u;
  80. if (u > 9) {
  81. SUMCHECK(tmp, sum, i, u, m);
  82. }
  83. }
  84. }
  85. } while (1);
  86. pi(tmp);
  87. }
  88.  
  89. return 0;
  90. }
  91.  
  92.  
Success #stdin #stdout 0s 6156KB
stdin
    5 2
    4000
    3000
    1000
    2000
    5000
    10000
    3000
stdout
9000
3000