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 forn(i,n) for(int i=0;i<n;++i)
//#define pi pair<int,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
struct pi {
int f,s,i;
pi(int a, int b) {
f=a,s=b,i=0;
}
pi(){}
};
bool foo(pi a, pi b) {
return a.f*b.s < b.f*a.s;
}
void insert(vector<int>&v, int x) {
if (!v.size() || x>=v.back()) {
v.pb(x); return;
}
int i=0;
while (x>v[i]) ++i;
int t=x;
while (i<v.size()) {
int z=t;
t=v[i];
v[i]=z;
++i;
}
v.pb(t);
}
bool zzz(pi a, pi b) {
return a.f<b.f;
}
void solve() {
int n,w; cin>>n>>w;
vector<pi> a(n); forn(i,n) { cin>>a[i].f>>a[i].s; a[i].i=i;}
sort(all(a),foo);
int ans=-1, best; pi frac;
int sum=0;
priority_queue<int> q;
forn(i,n) {
sum+=a[i].s;
q.push(a[i].s);
while (sum*a[i].f > w*a[i].s) {
sum-=q.top(); q.pop();
}
if ((int)(q.size()) > ans) {
ans=q.size();
best=i;
frac = { sum*a[i].f, a[i].s };
}
if ((int)(q.size()) == ans) {
if ( sum*a[i].f*frac.s < frac.f*a[i].s ) {
best=i;
frac = { sum*a[i].f, a[i].s };
}
}
}
cout<<ans<<'\n';
vector<pi> z;
forn(i,best+1) z.pb({a[i].s,a[i].i});
sort(all(z),zzz);
sum=0;
int i=best;
vector<int> ok;
forn(j,i+1) {
int x = (sum+z[j].f)*a[i].f;
int y = a[i].s;
if (foo( {w,1}, {x,y} )) break;
sum+=z[j].f;
ok.pb(z[j].s);
}
sort(all(ok));
for(auto&x:ok) cout<<x+1<<'\n';
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
Compilation message (stderr)
hiring.cpp: In function 'void insert(std::vector<long long int>&, long long int)':
hiring.cpp:32:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | while (i<v.size()) {
| ~^~~~~~~~~
hiring.cpp: In function 'void solve()':
hiring.cpp:83:27: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
83 | int x = (sum+z[j].f)*a[i].f;
| ^
hiring.cpp:68:35: warning: 'frac.pi::first' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | if ( sum*a[i].f*frac.s < frac.f*a[i].s ) {
| ^
hiring.cpp:68:19: warning: 'frac.pi::second' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | if ( sum*a[i].f*frac.s < frac.f*a[i].s ) {
| ^
# | 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... |