QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408107 | #6416. Classical Scheduling Problem | grass8cow# | WA | 81ms | 8532kb | C++17 | 2.8kb | 2024-05-09 18:34:43 | 2024-05-09 18:34:45 |
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;
}
}
}
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: 0ms
memory: 8504kb
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
Wrong Answer
time: 81ms
memory: 8532kb
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...
output:
7 8 3 9 12 14 15 16 18 21 53 53 1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 12 12 1 2 4 5 6 7 8 12 13 14 15 16 7 15 8 11 13 14 21 24 26 28 29 33 37 38 40 41 43 10 10 5 7 9 10 12 15 19 22 28 ...
result:
wrong answer topic 11 learned more than once (test case 22)