题目链接
思路:按a值进行排序,如果发现当前时间和大于T了,就优先删除t值较大的。
#include<bits/stdc++.h>
using namespace std;
const int maxn =2e5+1;
#define lowbit(i) (i)&(-i)
typedef long long ll;
struct cxk{
int a,t,id;
friend bool operator<(cxk x,cxk y)
{
return x.t<y.t;
}
}s[maxn];
ll ans=0,T,c[maxn],sum;
priority_queue<cxk>q;
bool cmp(const cxk &a,const cxk &b)
{
return a.a>b.a;
}
void update(int x,int v)
{
while(x<maxn) c[x]+=v,x+=lowbit(x);
}
ll query(int x)
{
ll res=0;
while(x>0) res+=c[x],x-=lowbit(x);
return res;
}
int main()
{
int n;
scanf("%d%lld",&n,&T);
for(int i=1;i<=n;++i)
scanf("%d %d",&s[i].a,&s[i].t),s[i].id=i;
sort(s+1,s+1+n,cmp);
for(int i=1;i<=n;++i)
{
sum+=s[i].t;
update(s[i].a,1);
q.push(s[i]);
while(!q.empty()&&sum>T) sum-=q.top().t,update(q.top().a,-1),q.pop();
int size=q.size();
ans=max(ans,query(n)-query(size-1));
}
printf("%lld\n",ans);
memset(c,0,sizeof(c));
while(!q.empty()) q.pop();
sum=0;
for(int i=1;i<=n;++i)
{
sum+=s[i].t;
update(s[i].a,1);
q.push(s[i]);
while(!q.empty()&&sum>T) sum-=q.top().t,update(q.top().a,-1),q.pop();
int size=q.size();
if(ans==query(n)-query(size-1))
{
printf("%d\n",q.size());
while(!q.empty()) printf("%d ",q.top().id),q.pop();
return 0;
}
}
}