QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408109 | #6416. Classical Scheduling Problem | grass8cow# | RE | 2ms | 8592kb | C++17 | 2.8kb | 2024-05-09 18:36:09 | 2024-05-09 18:36:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;ll K;
struct qq{
ll a;int b,id;
}e[201000];
struct SGT{
ll s1[800100],s2[801000];
void sc(int p){
int l=(p<<1),r=(p<<1|1);
s1[p]=s1[l]+s1[r],s2[p]=s2[l]+s2[r];
}
void build(int p,int l,int r,int z){
if(l==r){
if(z)s1[p]=1,s2[p]=e[l].a;
else s1[p]=s2[p]=0;
return;
}
int mid=(l+r)>>1;build(p<<1,l,mid,z),build(p<<1|1,mid+1,r,z);
sc(p);
}
inline void up(int p,int l,int r,int x,int z){
if(l==r){
if(z)s1[p]=1,s2[p]=e[l].a;
else s1[p]=s2[p]=0;
return;
}
int mid=(l+r)>>1;
if(x<=mid)up(p<<1,l,mid,x,z);
else up(p<<1|1,mid+1,r,x,z);
sc(p);
}
inline ll kth(int p,int l,int r,int k){
if(!k)return 0;
if(l==r)return s2[p];
int mid=(l+r)>>1;
if(k<=s1[p<<1])return kth(p<<1,l,mid,k);
return s2[p<<1]+kth(p<<1|1,mid+1,r,k-s1[p<<1]);
}
}T[2];
#define pb push_back
vector<int>G[201000];
bool vis[201000];
void sol(){
scanf("%d%lld",&n,&K);
for(int i=1;i<=n;i++)scanf("%lld%d",&e[i].a,&e[i].b),vis[i]=0,e[i].id=i,G[i].clear();
sort(e+1,e+n+1,[&](qq x,qq y){return x.a<y.a;});
for(int i=1;i<=n;i++)G[e[i].b].pb(i);
T[0].build(1,1,n,1),T[1].build(1,1,n,0);
ll ns=0;
int ans=0,nt=0,all=0;
for(int i=1;i<=n;i++){
ns+=e[i].a;if(ns>K)break;
nt+=(e[i].b<i);
for(int o:G[i])T[0].up(1,1,n,o,0),T[1].up(1,1,n,o,1),nt+=(o<=i),all++;
int l=nt,r=min(i,all);
while(l<=r){
int mi=(l+r)>>1;
if(T[0].kth(1,1,n,i-mi)+T[1].kth(1,1,n,mi)<=K)
ans=max(ans,mi),l=mi+1;
else r=mi-1;
}
}
printf("%d\n",ans);
if(!ans){puts("0");puts("");return;}
T[0].build(1,1,n,1),T[1].build(1,1,n,0);
ns=0,nt=0,all=0;
for(int i=1;i<=n;i++){
ns+=e[i].a;if(ns>K)break;
nt+=(e[i].b<i);
for(int o:G[i])T[0].up(1,1,n,o,0),T[1].up(1,1,n,o,1),nt+=(o<=i),all++;
int l=nt,r=min(i,all),jx=-1;
while(l<=r){
int mi=(l+r)>>1;
if(T[0].kth(1,1,n,i-mi)+T[1].kth(1,1,n,mi)<=K)jx=l,l=mi+1;
else r=mi-1;
}
if(jx==ans){
int st=0;
for(int j=1;j<=n;j++)
if(e[j].b<=i&&st<jx)st++,vis[e[j].id]=1;
assert(st==jx);
st=0;
for(int j=1;j<=n;j++)
if(e[j].b>i&&st<i-jx)st++,vis[e[j].id]=1;
assert(st==i-jx);
printf("%d\n",i);
for(int j=1;j<=n;j++)if(vis[j])printf("%d ",j);puts("");
return;
}
}
assert(0);
}
int main(){
int T;scanf("%d",&T);while(T--)sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8592kb
input:
2 4 100 20 1 40 4 60 3 30 3 1 5 10 1
output:
2 3 1 2 4 0 0
result:
ok ok, 2 test cases (2 test cases)
Test #2:
score: -100
Runtime Error
input:
10000 21 1892 174 13 604 15 170 2 413 11 899 2 531 12 651 17 553 9 429 8 837 14 937 12 577 7 532 11 19 2 173 10 165 6 762 15 221 6 945 13 302 19 7 3 54 26066 812 31 432 24 240 37 171 39 204 47 174 30 569 1 467 5 624 42 734 35 907 3 568 23 802 40 991 32 119 13 187 27 739 42 891 14 550 44 374 16 483 1...