建议添加二分标签
查看原帖
建议添加二分标签
1152035
Yang_Zirui楼主2024/10/5 15:24

这道题用二份答案也能做

AC代码如下

#include <bits/stdc++.h>
using namespace std;
long long a,b,c,l=1,r=1e9;
bool check(int x){
	long long c1=c,i=0;
	long long a1=a;
	long long b1=b;
	while(c1>=0){
		if(i==x) return true;
		a1-=(i+1);
		b1-=(i+1);
		if(a1<0){
			c1-=(0-a1);
			a1=0;
		}
		if(b1<0){
			c1-=(0-b1);
			b1=0;
		}
		i++;
	}
	return false;
}
int main(){
//	freopen("t.in","r",stdin);
//	freopen("t.out","w",stdout);
	scanf("%lld%lld%lld",&a,&b,&c);
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	printf("%lld",l-1);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
} 
2024/10/5 15:24
加载中...