-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
Describe
-
Wood Factory There are some logs, now want to cut these wood into some of the same length of small pieces of wood, need to get the number of small pieces is given. Of course, the longer we want to get the smaller segment the better, your task is to calculate the maximum length of the small piece of wood that can be obtained.
The unit of wood length is centimeters. The length of the log is a positive integer, and the length of the small piece of wood we require to be cut is also required to be a positive integer.
-
Input
-
The first line is two positive integers n and K(1≤ n ≤ 10000, 1≤ K ≤10000),n is the number of logs,K is the number of small segments that need to be obtained.
The next N rows, each line has a positive integer between 1 and 10000, representing the length of a log.
-
Output
-
The maximum length of the small segment that the output can be cut. If the 1 cm length of the small segment can not be cut out, output "0".
-
Sample input
-
3 7232124456
-
Sample output
-
114
-
Source
-
NOIP 2004
This question and ch0111/04 is the same practice, here is detailed introduction.
Ps put N, k input comment out can get 1 points!
1#include <stdio.h>2 intlen[10010]={0};3 intMain ()4 {5 inti;6 intmax=-1;7 intN,k,ans,mid;8 intr,l;9scanf"%d%d",&n,&k);Ten for(i=0; i<n;i++) One { Ascanf"%d",&len[i]); - if(Len[i]>max) max=Len[i]; - } theL=0; -r=max+1; - while(L +1<R)//two points to find the right length - { +ans=0; -Mid= (L+R)/2; + for(i=0; i<n;i++) Aans+=len[i]/mid; at if(ans>=k) l=mid; // pay attention to the condition control here. - ElseR=mid; - } -printf"%d", L); - return 0; -}
Openjudge NOI test Bank ch0111/t1776 Wood Processing