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 mkt make_tuple
#define debug printf
#define all(x) x.begin(),x.end()
#define lp(i,a,b) for(int i = a ; i< b ; i++)
#define ss second
#define ff first
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mk make_pair
const int MAXN = 5e5+10 ;
using namespace std ;
struct Seg
{
int s[MAXN*4] ;
ll v[MAXN*4] ;
Seg() { memset(v, 0, sizeof v) ; memset(s,0,sizeof s) ; }
int m(int l, int r) { return (l+r)>>1 ; }
void upd(int pos, int l, int r, int idx, ll val )
{
v[pos] += val ;
s[pos] ++ ;
if( l == r ) return ;
if( idx <= m(l,r) ) upd(pos<<1,l,m(l,r),idx,val) ;
else upd( (pos<<1)|1 , m(l,r)+1, r, idx, val ) ;
}
int bb(int pos, int l, int r, ll soma )
{
if( l == r && v[pos] > soma ) return 0 ;
else if( l == r && v[pos] <= soma ) return 1 ;
if( v[pos<<1] <= soma ) return s[pos<<1] + bb( (pos<<1)|1 , m(l,r)+1, r, soma - v[pos<<1] ) ;
return bb(pos<<1,l,m(l,r) , soma) ;
}
};
int N ;
int S[MAXN] , Q[MAXN] , vet[MAXN] ;
int idx[MAXN] , compressao[MAXN] ;
int resp[MAXN] ;
ll cur_soma ;
vector<int> ans ;
vector<pii> v ;
ll W ;
Seg seg ;
bool cmp(int i, int j)
{
int val1 = S[i] * Q[j] ;
int val2 = S[j] * Q[i] ;
if( val1 != val2 ) return val1 < val2 ;
return Q[i] <= Q[j] ;
}
bool cmp2(int i , int j)
{
if( Q[i] == Q[j] ) return S[i] <= S[j] ;
return Q[i] < Q[j] ;
}
int main()
{
scanf("%d %lld", &N , &W ) ;
lp(i,1,N+1) scanf("%d %d", &S[i] , &Q[i]) ;
lp(i,1,N+1) vet[i] = idx[i] = i ;
sort(vet+1, vet+1+N,cmp) ;
sort(idx+1, idx+1+N, cmp2 ) ;
lp(i,1,N+1) compressao[ idx[i] ] = i ;
lp(i,1,N+1)
{
seg.upd( 1 , 1 , N , compressao[ vet[i] ] , Q[ vet[i] ] ) ;
ll procuro = ( W*1LL*Q[ vet[i] ] )/(1LL*S[ vet[i] ]) ;
resp[i] = seg.bb( 1 , 1 , N , procuro ) ;
}
int mx = *max_element(resp+1, resp+1+N);
printf("%d\n" , mx ) ;
lp(i,1,mx+1) printf("%d\n", vet[i] ) ;
}
Compilation message (stderr)
hiring.cpp: In function 'int main()':
hiring.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %lld", &N , &W ) ;
~~~~~^~~~~~~~~~~~~~~~~~~~~
hiring.cpp:82:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
lp(i,1,N+1) scanf("%d %d", &S[i] , &Q[i]) ;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |