fork download
  1. #include <stdio.h>
  2.  
  3. void solve()
  4. { int n,m,d[100],ans=0,i,j,k,t; scanf("%d%d",&n,&m);
  5. for (i=0;i<n;i++) scanf("%d",&d[i]);
  6. for (i=0;i<n-2;i++)
  7. for (j=i+1;j<n-1;j++)
  8. for (k=j+1;k<n;k++)
  9. if ((t=d[i]+d[j]+d[k])<=m && t>ans) ans=t;
  10. printf("%d\n",ans);
  11. }
  12.  
  13. void init() /* Define function init() to do global intialization if needed */
  14. {
  15.  
  16. }
  17.  
  18. /******************************************************************************/
  19. /* */
  20. /* DON'T MODIFY main() function anyway! */
  21. /* */
  22. /******************************************************************************/
  23.  
  24. #include <stdio.h>
  25.  
  26. void solve(); /* write function solve() to process one case of the problem */
  27.  
  28. int main()
  29. { int i,t;
  30. init();
  31. scanf("%d\n",&t);
  32. for (i=0;i<t;i++)
  33. {
  34. printf("case #%d:\n",i);
  35. solve();
  36. }
  37. return 0;
  38. }
  39.  
  40.  
Success #stdin #stdout 0.01s 1724KB
stdin
10
5 21
5 6 7 8 9
10 500
93 181 245 214 315 36 185 138 216 295
3 10
1 1 1
10 100
34 24 29 28 3 45 15 54 1 44
5 1000
325 213 23 622 326
20 50000
1791 128 16886 2712 1236 26668 7339 9606 4635 2140 15692 13397 14047 15551 30039 21715 8898 6973 21673 8897
55 133333
190 28738 25989 4145 20064 18903 19458 26289 16366 361 12356 6220 3547 9214 8337 1644 3551 26115 11697 18720 8564 1479 24944 22935 13400 15869 17695 19625 19214 18494 30740 7502 8541 28549 22053 1828 22735 12977 11825 28909 14131 30471 2200 26383 29979 19117 32190 9747 7263 14128 7308 13607 30360 9215 24814
100 250000
60969 47586 99051 12541 27785 95462 7815 81374 9845 39648 93463 70687 91555 96527 97067 10215 32987 18117 54373 19122 87067 80200 21437 86033 9108 76274 64734 74760 22667 61777 19175 51439 5561 99048 34762 10258 79563 27085 96433 13040 49058 19081 3604 60960 14131 7099 89572 64743 98601 77141 6788 37955 32094 12509 48202 78724 65318 48878 45058 80621 44965 26388 4780 71064 63443 39700 41081 16655 95615 29761 14258 30644 43049 61160 51857 54746 19943 79557 58021 77417 10017 8971 34354 75677 3381 39840 67247 87848 7891 23039 39943 2924 84386 77877 35832 38530 37849 76676 89015 92054
3 30000
1000 1000 1000
4 40
10 10 10 10
stdout
case #0:
21
case #1:
497
case #2:
3
case #3:
100
case #4:
971
case #5:
49699
case #6:
93401
case #7:
249987
case #8:
3000
case #9:
30