-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicrosoft_one.cpp
More file actions
46 lines (46 loc) · 1.02 KB
/
Microsoft_one.cpp
File metadata and controls
46 lines (46 loc) · 1.02 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
using namespace std;
int check(int mid, int N, int W, int H, int a[])
{
int page = 0;
int w = W / mid;
int h = H / mid;
int p_w,p_w_y,hang=0;
for(int i=0;i<N;i++){
p_w = a[i] / w;
p_w_y = a[i] % w;
hang = hang + p_w;
if(p_w_y != 0)hang ++;
}
page = hang / h;
if(hang % h != 0)page ++;
return page;
}
int main()
{
int mid = 0;
int n,T,N,P,W,H,ans=0,cnt;
int a[100];
while(cin>>n){
for(int T=1;T<=n;T++){
cin>>N>>P>>W>>H;
for(int i=0;i<N;i++)
{
cin >> a[i];
}
int left=1, right=min(W,H);
while(left <= right){
mid = (left + right) / 2;
cnt = check(mid, N, W, H, a);
if(cnt > P){
right = mid - 1;
}else{
ans = mid;
left = mid + 1;
}
}
cout<<ans<<endl;
}
}
return 0;
}