AcWing 4956. 冶炼金属
原题链接
简单
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=10010;
typedef long long ll;
ll a[N],n;
ll res=0,b[N];
bool check(ll mid){
ll sum=0;
for(ll i=1;i<=n;i++)
sum+=a[i]/mid;
if(sum>res)
return true;
else return false;
}
bool check1(ll mid){
ll sum=0;
for(ll i=1;i<=n;i++)
sum+=a[i]/mid;
if(sum>=res)
return true;
else return false;
}
int main(){
cin>>n;
for(ll i=1;i<=n;i++){
cin>>a[i]>>b[i];
res+=b[i];
}
ll l=1,r=1e9;
while(l<r){
ll mid=l+r>>1;
if(check(mid))
l=mid+1;
else r=mid;
}
ll l1=1,r1=1e9;
while(l1<r1){
ll mid=(l1+r1+1)/2;
if(check1(mid))
l1=mid;
else r1=mid-1;
}
cout<<r<<' '<<r1;
return 0;
}