hiho week 148 register

Ended

Participants:382

Verdict:Accepted
Score:100 / 100
Submitted:2017-05-05 15:37:54

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <iostream>
using namespace std;
int a[1010],n,w,h;
int f(int x){
    int sum=0;
    if((w/x==0)||(h/x==0)) return 1e7;
    for(int i=0;i<n;i++){
        if(a[i]%(w/x) != 0) sum++;
        sum += a[i]/(w/x);
    }
    return (sum%(h/x)==0?0:1)+sum/(h/x);
}
int main(){
    int T,p;
    scanf("%d", &T);
    while(T--){
        scanf("%d%d%d%d", &n, &p, &w, &h);
        for(int i=0;i<n;i++)scanf("%d", &a[i]);
        int l=1,r=1000000;
        while(l+1<r){
            int mid = (l+r)>>1;
            if(f(mid) <= p) l = mid;
            else r = mid;
        }
        cout<<l<<endl;
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX