文章

冶炼金属

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,a,b,ans,minn=-1,maxn=-1,i,tmp;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a>>b;
		ans=a/b;
		tmp=ans;
		while(a/(tmp-1)==b){
			tmp--;
		}
		if(minn==-1){
			minn=tmp;
		}else {
			minn=max(tmp,minn);
		}
		
		tmp=ans;
		while(a/(tmp+1)==b){
			tmp++;
		}
		maxn=min(tmp,maxn);
		if(maxn==-1){
			maxn=tmp;
		}else {
			maxn=min(maxn,tmp);
			
		}
//		cout<<minn<<' '<<maxn<<endl;
	}
	cout<<minn<<' '<<maxn<<endl;
	return 0;
}

License:  CC BY 4.0