听灌佬多(求条玄关)
  • 板块灌水区
  • 楼主CXH114
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/19 10:17
  • 上次更新2025/1/19 12:48:40
查看原帖
听灌佬多(求条玄关)
1082359
CXH114楼主2025/1/19 10:17

题目

#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;
}

2025/1/19 10:17
加载中...