区间合并 左端点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;
}
标签:cnt,last,cout,int,合并,端点,false,first 来源: https://www.cnblogs.com/liang302/p/16597333.html