This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define N 1<<19
typedef long long ll;
#define int ll
using namespace std;
struct fenwick_tree{
ll T[N]{};
void upd(int x,int p){
while(x<N)
T[x]+=p,x+=x&-x;
}
ll qr(int x){
int ans=0;
while(x)
ans+=T[x],x-=x&-x;
return ans;
}
} X,cnt;
int h,g,p[N],CC,CC2;
pair<ll,ll>b;
void stuff(ll x,int i,ll A,ll B){
int l=0,r=5e5,res=0;
while(l<=r){
int mid=l+r>>1;
if(X.qr(mid)<=x)
l=mid+1,res=mid;
else r=mid-1;
}
ll K=cnt.qr(res),C=X.qr(res);
if(K>h||K==h&&b.first*B>b.second*A*C)
h=K,b={A*C,B},g=i;
}
#undef int
signed main(){
cin.tie(0)->sync_with_stdio(0);
set<pair<int,int>>st;
vector<tuple<int,int,int>>v;
int n;
ll w;
cin>>n>>w;
for(int i=1;i<=n;i++){
int q,s;
cin>>s>>q;
st.insert({q,i});
v.push_back({q,s,i});
}
for(auto[q,i]:st)
p[i]=++CC;
sort(v.begin(),v.end(),[](auto a,auto b){
return get<1>(a)*get<0>(b)<get<0>(a)*get<1>(b);
});
for(auto[q,s,i]:v){
X.upd(p[i],q);
cnt.upd(p[i],1);
stuff(w*q/s,++CC2,s,q);
}
vector<pair<int,int>>v2;
for(int i=0;i<g;i++)
v2.push_back({get<0>(v[i]),get<2>(v[i])});
sort(v2.begin(),v2.end());
cout<<h<<'\n';
for(int i=0;i<h;i++)
cout<<v2[i].second<<'\n';
}
Compilation message (stderr)
hiring.cpp: In function 'void stuff(ll, ll, ll, ll)':
hiring.cpp:24:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | int mid=l+r>>1;
| ~^~
hiring.cpp:30:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
30 | if(K>h||K==h&&b.first*B>b.second*A*C)
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |