- #include
- using namespace std;
- using VI = vector<int>;
- using ll = long long;
- using PII = pair
; - const ll mod = 998244353;
-
- int n;
-
- int main(){
- cin>>n;
- vector
q; - for(int i = 0 ; i < n ; i++){
- ll x,y;
- cin>>x>>y;
- q.push_back({x,x+y});
- }
- sort(q.begin() , q.end());
- priority_queue
,greater>pq; - int j = 0;
- ll now = 1;
- int res = 0;
- while(j < n || pq.size()){
- if(!pq.size() && q[j].first >= now && j < n){ //如果没有可操作的物品,就拿出一个物品
- now = q[j].first;
- pq.push(q[j].second);
- j++;
- }
- while(j < n && q[j].first <= now){//把所有可操作的物品加入
- pq.push(q[j].second);
- j++;
- }
- //auto x = pq.top();
- while(pq.size() && pq.top() < now)pq.pop();//去掉不可操作的物品
- if(pq.size()){
- pq.pop();//更新答案
- now++;
- res++;
- }
- }
-