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>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, w;
pii A[500005];
bool cmp(pii a, pii b){
return ((long double)a.fi / (long double)a.se.fi) < ((long double)b.fi / (long double)b.se.fi);
}
struct node{
int s, e, m, val, val2;
node *l, *r;
node(int _s, int _e){
s = _s, e = _e, m = (s + e) >> 1;
if(s != e)l = new node(s, m), r = new node(m+1, e);
val = val2 = 0;
}
void upd(int p){
if(s == e)val += s, val2++;
else{
if(p <= m)l->upd(p);
else r->upd(p);
val = l->val + r->val;
val2 = l->val2 + r->val2;
}
}
pi qry(int a, int b){
if(s == a && e == b)return {val,val2};
else if(b <= m)return l->qry(a, b);
else if(a > m)return r->qry(a, b);
else {
pi lft = l->qry(a, m), rgt = r->qry(m+1, b);
return {lft.fi + rgt.fi, lft.se + rgt.se};
}
}
}*root;
void solve(){
cin >> n >> w;
int mx = 0;
for(int i=1;i<=n;i++)cin >> A[i].fi >> A[i].se.fi, A[i].se.se = i, mx = max(mx, A[i].se.fi);
root = new node(1, mx);
sort(A+1, A+n+1, cmp);
vector <pi> v;
pair<int, long double> ans2 = {0, 0.0L};
vector <int> fin;
int in = 0;
for(int i=1;i<=n;i++){
int x = w * A[i].se.fi / A[i].fi;
x -= A[i].se.fi;
if(x < 0){
root->upd(A[i].se.fi);
continue;
}
/*
vector <int> tmp = {A[i].se.se};
for(auto [j, k] : v){
if(x >= j)x -= j, tmp.push_back(k);
}
v.push_back({A[i].se.fi, A[i].se.se});
sort(v.begin(), v.end());
int used = w * A[i].se.fi / A[i].fi - x;
long double brub = (long double)(used * A[i].fi) / A[i].se.fi;
if((int)tmp.size() > ans.fi || ((int)tmp.size() == ans.fi && ans.se < -brub))ans = {(int)tmp.size(), -brub}, fin = tmp;
*/
int lo = 1, hi = mx, ans = mx + 1, val = 0;
while(lo <= hi){
int mid = (lo + hi) >> 1;
pi res = root->qry(1, mid);
if(res.fi >= x)ans = mid, hi = mid - 1;
else lo = mid + 1;
}
if(ans != 1)val = root->qry(1, ans - 1).se;
if(ans != mx + 1){
int left = root->qry(ans, ans).se;
x -= root->qry(1, ans - 1).fi;
int mn = min(left, x / ans);
val += min(x/ans, left);
x -= mn * ans;
}
int used = w * A[i].se.fi / A[i].fi - x;
long double brub = (long double)(used * A[i].fi) / A[i].se.fi;
val++;
ans2 = max(ans2, {val, -brub});
if(ans2 == make_pair(val, -brub))in = i;
root->upd(A[i].se.fi);
}
/*
cout << fin.size() << '\n';
for(auto i : fin)cout << i << '\n';
*/
cout << ans2.fi << '\n';
if(ans2.fi == 0)return;
for(int i=1;i<in;i++){
v.push_back(A[i].se);
}
sort(v.begin(), v.end());
int x = w * A[in].se.fi / A[in].fi;
x -= A[in].se.fi;
fin.push_back(A[in].se.se);
for(auto [j, k] : v){
if(x >= j)x -= j, fin.push_back(k);
}
for(auto i : fin)cout << i << '\n';
assert((int)fin.size() == ans2.fi);
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
hiring.cpp:122:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
122 | main(){
| ^~~~
# | 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... |