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, MAXV=1e9+10;////
struct st{
ll i, s, q;
}t[MAX];
ll n, w;
bool spr(ll x){
ll sum=0;
multiset<ll>m;
for(ll i=1; i<=x; i++)
sum+=t[i].q, m.insert(t[i].q);
ll mini=MAXV;
for(ll i=x; i<=n; i++){
if(i>x){
auto it=m.end();
it--;
if(*it>t[i].q){
sum-=*it, sum+=t[i].q;
m.erase(it), m.insert(t[i].q);
}
}
mini=min(mini, sum);
if(w*t[i].q>=sum*t[i].s)
return true;
}
return false;
}
ll bin(){
ll pocz=0, kon=n, sr, wyn=0;
while(pocz<=kon){
sr=(pocz+kon)/2;
if(spr(sr))
wyn=sr, pocz=sr+1;
else
kon=sr-1;
}
return wyn;
}
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;
t[i].i=i;
}
sort(t+1, t+n+1, [](st a, st b){
ll la=a.s/__gcd(a.s, a.q), ma=a.q/__gcd(a.s, a.q);
ll lb=b.s/__gcd(b.s, b.q), mb=b.q/__gcd(b.s, b.q);
ll nla=la*mb, nlb=lb*ma;
return nla<nlb;
});
cout<<bin()<<"\n";;
}
# | 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... |