社区讨论

全wa了,求助谢谢

P2107小 Z 的 AK 计划参与者 3已保存回复 4

讨论操作

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

当前回复
4 条
当前快照
1 份
快照标识符
@lo9f8wvc
此快照首次捕获于
2023/10/28 10:27
2 年前
此快照最后确认于
2023/10/28 10:27
2 年前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
struct room{
    ll pos;
    int t;
}a[100005];
ll ans,akcnt,tim;
priority_queue<ll> q;
bool cmp(room aa,room bb){
    return aa.pos<bb.pos;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%lld%d",&a[i].pos,&a[i].t);
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        akcnt++;
        tim+=a[i].pos-a[i-1].pos;
        tim+=a[i].t;
        q.push(a[i].t);
        while(tim>m&&!q.empty()){
            akcnt--;
            tim-=q.top();
            q.pop();
        }
        if(tim>m) break;
        ans=max(akcnt,ans);
    }
    printf("%lld\n",ans);

    return 0;
}

回复

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

正在加载回复...