加载中...

区间合并 左端点1右端点-1的等待cnt=0的情况

牛客第一题https://ac.nowcoder.com/acm/contest/33186/A

signed main(){
//	ios::sync_with_stdio(false);
//    cin.tie(0),cout.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		v.push_back({a-b,1});
		v.push_back({a+b,-1});
	}
	sort(v.begin(),v.end(),cmp);
	int res=0;
	int cnt=0,last=v[0].first;
	bool space=false;
	for(auto t:v){
		if(cnt==0){
			res+=t.first-last;

		}
		cnt+=t.second;
		last=t.first;
	}	
	cout<<res;
	return 0;
}
posted @ 2022-08-18 00:20  liang302  阅读(24)  评论(0编辑  收藏  举报