跳到正文

个人记录

ccc

zjn2012约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月7日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct P{
	long long a,b;
};
P a[N];
bool cmp(P a,P b){
	return a.a<b.a;
}
priority_queue<long long> q;
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].a>>a[i].b;
	}
	sort(a+1,a+1+n,cmp);
	long long ans=0;
	for(int i=1;i<=n;i++){
		if(q.size()&&-q.top()<a[i].a){
			q.pop();
			q.push(-a[i].b);
		}else{
			ans++;
			q.push(-a[i].b);
		}
	}
	cout<<ans;
	return 0;
} /*
3
-1 1
2 4
3 5

*/
原文