Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2010
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. The world famous online bookstore SiruSeri.Com has announced an awards scheme for its
  2. customers. As an inaugural offer, every customer who has bought a book during the past
  3. year will receive a gift coupon that can be used to order books free from the bookstore.
  4. Each coupon has a fixed value. The catch is that the coupon must be used to buy three
  5. different books, such that the total value of the books exactly adds up to the value of the
  6. coupon.
  7. For instance, suppose that the coupon has value 600 and the books available in the
  8. catalogue cost 136, 411, 211, 200, 275, 189, 232 and 375. Then, one possible way to use the
  9. coupon is to order the books costing 136, 275 and 189, which add up to 600, the value of
  10. the coupon. The coupon cannot be used to order three copies of the book costing 200 or
  11. one copy of the book costing 136 and two copies of the book costing 232, though both these
  12. orders add up to 600, because the coupon must be used to buy three different books. The
  13. books costing 189 and 411 add up to 600, but this is not a valid order because it consists of
  14. only two books.
  15. You will be given the value of the gift coupon and the costs of all books available in the
  16. catalogue of SiruSeri.Com. Your task is to assemble an order consisting of three different
  17. books whose total value matches that of the coupon. If there is more than one possible
  18. order, it suffices to report any one.
  19. Input format
  20. The first line consists of two integers N and M, where N is the total number of books
  21. available in the catalogue of SiruSeri.Com and M is the value of the gift coupon. This is
  22. followed by N lines of input, lines 2,3,. . . ,N+1, each consisting of a single integer giving the
  23. value of one book in the catalogue.
  24. Output format
  25. Your output should consist of three lines, each containing one integer, representing the costs
  26. of three different books that make up a valid order with total valueM. The costs of the three
  27. books should be listed in ascending order. If more than one solution is possible, it suffices
  28. to report any one. If no solution is possible, your output should consist of the number 0 on
  29. each of the three lines.
  30. Test data
  31. You may assume that 3  N  8000. In 30% of the inputs, 3  N  300.
  32. The value of the gift coupon M is a positive integer. The cost of each book is a positive
  33. integer. No two books have the same cost.
  34. 1
  35. Example
  36. Here is the sample input and output corresponding to the example discussed above.
  37. Sample input
  38. 8 600
  39. 136
  40. 411
  41. 211
  42. 200
  43. 275
  44. 189
  45. 232
  46. 375
  47. Sample output
  48. 136
  49. 189
  50. 275
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement