Input may contain multiple test cases. The first line is an integer TASKS, representing the number of test cases. For each test case, the first line contains four integers N, P, W and H, as described above. The second line contains N integers a1, a2, … aN, indicating the number of characters in each paragraph.
For all test cases, 1 <= N <= 103, 1 <= W, H, ai <= 103, 1 <= P <= 106,
There is always a way to control the number of pages no more than P.
输出
For each testcase, output a line with an integer Ans, indicating the maximum font size Steven can set.
intcalLines(int char_each_line){ int total = 0; for( int i = 0 ; i < n ; i ++ ){ total += paragraphs[i] / char_each_line; if( paragraphs[i] % char_each_line != 0){ total ++; } } return total; }
voidsolve(){ int min = (w>h)?h:w; int currentS = 1; while(currentS <= min){ int char_each_line = w/currentS; int lines_each_page = h/currentS; int needLines = calLines(char_each_line); int pages = needLines / lines_each_page; if(needLines%lines_each_page!=0){ pages++; } if( pages <= p && currentS > maxn ){ maxn = currentS; } currentS ++; } }
intmain(){ int caseNumber = 0; cin >> caseNumber; int currentCase = 0; while (currentCase < caseNumber) { maxn = 0; cin>>n>>p>>w>>h; for(int i = 0 ; i < n ; i ++){ cin>>paragraphs[i]; } solve(); cout<<maxn<<endl; currentCase ++; } return0; }