HDU 2124 Repair the Wall

Source: Internet
Author: User

Repair the Wall Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 3076 Accepted Submission (s): 1504


problem DescriptionLong time ago, Kitty lived in a small village. The air was fresh and the scenery were very beautiful. The only thing that troubled she is the typhoon.

When the typhoon came, everything is terrible. It kept blowing and raining for a long time. And what made the situation worse is that's all of the Kitty's walls were made of wood.

One day, Kitty found that there is a crack in the wall. The shape of the crack is
A rectangle with the size of 1xL (inch). Luckly Kitty got N blocks and a saw (saw) from her neighbors.
The shape of the blocks were rectangle too, and the width of all blocks were 1 inch. So, with the help of saw, Kitty could cut some of the blocks (of course she could use it directly without cutting) and Put them in the crack, and the wall is repaired perfectly, without any gap.

Now, Kitty knew the size of each blocks, and wanted to use as fewer as possible of the blocks to repair the wall, could yo U help her?
 


InputThe problem contains many test cases, please process to the end of file (EOF).
Each test case contains the lines.
In the first line, there is integers L (0<l<1000000000) and N (0<=n<600) which
mentioned above.
In the second line, there is N positive integers. The ith integer Ai (0<ai<1000000000) means that the ith block have the size of 1xAi (in inch).
 


Outputfor each test case, print an integer which represents the minimal number of blocks is needed.
If Kitty could not repair the wall, just print "impossible" instead.
 


Sample Input5 2 1 


Sample Output2impossible 


AuthorLinle 


SourceHDU 2007-10 Programming Contest 


recommend

Whiskey


Note: Use the int variable to store the length of the block and the range beyond int.

1#include <cstdio>2#include <algorithm>3 using namespacestd;4 Const intMAXN =650;5 Long LongA[MAXN];6 intMain ()7 {8     Long LongL, sum, ans;9     intN;Ten      while(SCANF ("%lld%d", &l, &n) = =2) One     { Asum =0; Ans =0; -          for(inti =0; I < n; i++) -scanf"%lld", &a[i]); theSort (A, A +n); -         inti = n-1; -          while(Sum < L&&i >=0) -         { +ans++; Sum + = a[i--]; -         } +         if(Sum < L) printf ("impossible\n"); A         Elseprintf"%lld\n", ans); at     } -}

HDU 2124 Repair the Wall

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.