1 条题解

  • 0
    @ 2025-9-10 0:12:03

    C++ :

    #define MAXN 150010UL
    
    #define ll long long
    
    #include <algorithm>
    #include <cstdio>
    #include <queue>
    
    struct Point{
    	ll t1,t2;
    	friend bool operator < (Point a,Point b){return a.t1<b.t1;}
    	inline void in(){scanf("%lld%lld",&t1,&t2);return;}
    };
    
    std::priority_queue<Point> que;
    Point s[MAXN];
    int n,i;
    ll cur_time;
    
    inline bool comp(Point a,Point b){return a.t2<b.t2;}
    
    int main(){
    	scanf("%d",&n);
    	for(;i<n;i++) s[i].in();
    	for(std::sort(s,s+n,comp),i=0;i<n;i++){
    		if(cur_time+s[i].t1<=s[i].t2) que.push(s[i]),cur_time+=s[i].t1;
    		else if(s[i].t1<=que.top().t1&&cur_time+s[i].t1-que.top().t1<=s[i].t2) cur_time+=s[i].t1-que.top().t1,que.pop(),que.push(s[i]);
    	}
    	printf("%d",que.size());
    	return 0;
    }
    
    • 1

    信息

    ID
    3298
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者