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 pb push_back
#define fi first
#define se second
#define ll long long
const ll MAX=5e5+10, L=16;
const ll MAXV=1e18+10;
struct st{
int i, s, q, s1, q1;
}t[MAX];
int n;
ll w;
int minipos;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>w;
for(ll i=1; i<=n; i++){
cin>>t[i].s>>t[i].q;
int gcd=__gcd(t[i].s, t[i].q);
t[i].q1=t[i].q/gcd, t[i].s1=t[i].s/gcd;
t[i].i=i;
}
sort(t+1, t+n+1, [](st a, st b){
return a.s1*b.q1<b.s1*a.q1;
});
ll sum=0;
multiset<int>m;
long double mini=MAXV;
int maxi=0;
for(ll i=1; i<=n; i++){
m.insert(t[i].q), sum+=t[i].q;
while(sum*(ll)t[i].s>w*(ll)t[i].q){
auto it=m.end();
it--;
sum-=*it;
m.erase(it);
}
if(w*(ll)t[i].q>=sum*(ll)t[i].s){
if(int(m.size())>=maxi){
if(int(m.size())>maxi)
mini=MAXV;
maxi=max(maxi, int(m.size()));
if(mini>(long double)sum*t[i].s/(long double)t[i].q)
mini=(long double)sum*t[i].s/(long double)t[i].q, minipos=i;
}
}
}
cout<<maxi<<"\n";
multiset<pair<int,int>>m2;
for(int i=1; i<=minipos; i++)
m2.insert({t[i].q, t[i].i});
int ile=0;
for(multiset<pair<int,int>>::iterator it=m2.begin(); true; it++){
cout<<(*it).se<<"\n";
ile++;
if(ile==maxi)
break;
}
}
# | 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... |