二分a+b

chenyining 2023-03-11 11:01:25 25 返回题目

#include<bits/stdc++.h>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	int l=1,r=2e9,best=-1;
	while(l<=r){
		int mid=(l+r)/2;
		if(mid==a+b){
			best=mid;
			break;
		}else if(mid<a+b){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	cout<<best;
	return 0;
} 
{{ vote && vote.total.up }}