社区讨论

听灌佬多(求条玄关)

灌水区参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@m62znd6p
此快照首次捕获于
2025/01/19 10:18
去年
此快照最后确认于
2025/11/04 11:19
4 个月前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
struct Product{
    long long s,d;
};
bool cmp(Product x,Product y){
    return x.d<y.d;
}
vector<Product> a;
int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        Product t;
        long long x;
        cin>>t.s>>x;
        t.d=t.s+x;
        a.push_back(t);
    }
    sort(a.begin(),a.end(),cmp);
    long long now=a[0].s+1,ans=1;
    for(int i=1;i<n;i++){
        if(now<=a[i].d){
            if(now<a[i].s){
                now=a[i].s;
            }else{
                now+=1;
            }
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...