이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
struct Obj{
ll s; // min salary
ll q; // skill
int i;
};
bool cmp(Obj&a,Obj&b){
return a.s*b.q<b.s*a.q;
}
ll w;
int n;
const int TREE_SIZE=1<<19;
ll vals[TREE_SIZE];
ll valst[2*TREE_SIZE];
int present[2*TREE_SIZE];
void update_node(int node){
if(node<TREE_SIZE){
valst[node]=valst[2*node]+valst[2*node+1];
present[node]=present[2*node]+present[2*node+1];
}
}
void update(int i){
int node=TREE_SIZE+i;
node/=2;
while(node){
update_node(node);
node/=2;
}
}
void add(ll val){
int l=0,r=n;
while(l<r-1){
int m=(l+r)/2;
if(vals[m]>val||(vals[m]==val&&present[TREE_SIZE+m]))
r=m;
else
l=m;
}
present[TREE_SIZE+l]=1;
valst[TREE_SIZE+l]=vals[l];
update(l);
}
int get(int node,int rl,int rr,ll&cost,ll m1,ll m2){
if(rl==rr-1){
return 0;
}
int res=0;
int mid=(rl+rr)/2;
if((cost+valst[2*node])*m1<=w*m2){
cost+=valst[2*node];
res+=present[2*node];
res+=get(2*node+1,mid,rr,cost,m1,m2);
}else{
res+=get(2*node,rl,mid,cost,m1,m2);
}
return res;
}
int get(ll&cost,ll m1,ll m2){
return get(1,0,TREE_SIZE,cost,m1,m2);
}
void solve(){
cin>>n>>w;
vector<Obj>arr(n);
for(int i=0;i<n;i++){
cin>>arr[i].s>>arr[i].q;
arr[i].i=i+1;
vals[i]=arr[i].q;
}
sort(vals,vals+n);
for(int i=TREE_SIZE-1;i>0;i--)
update_node(i);
sort(arr.begin(),arr.end(),cmp);
int res=0;
int opt=0;
ll m1=0,m2=1; // spends m1/m2
for(int i=0;i<n;i++){
if(i)
add(arr[i-1].q);
ll cost=arr[i].q;
if(cost*arr[i].s>w*arr[i].q)
continue;
int cres=get(cost,arr[i].s,arr[i].q);
if(cres+1>res){
res=cres+1;
opt=i;
m1=cost*arr[i].s;
m2=arr[i].q;
}else if(cres+1==res){
if((__int128)cost*arr[i].s*m2<(__int128)m1*arr[i].q){
opt=i;
m1=cost*arr[i].s;
m2=arr[i].q;
}
}
}
cout<<res<<"\n";
if(res){
cout<<arr[opt].i<<"\n";
int i=opt;
vector<pair<ll,int>>vals;
for(int j=0;j<i;j++)
vals.emplace_back(arr[j].q,arr[j].i);
sort(vals.begin(),vals.end());
ll cost=arr[i].q;
int cres=0;
while(cres<(int)vals.size()){
if((cost+vals[cres].first)*arr[i].s<=w*arr[i].q){
cost+=vals[cres].first;
cout<<vals[cres].second<<"\n";
cres++;
}else{
break;
}
}
}
}
int main(){
ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
//freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
int t=1;//cin>>t;
while(t--)solve();
return 0;
}
/*
4 100
5 1000
10 100
8 10
20 1
2
2
3
3 4
1 2
1 3
1 3
3
1
2
3
3 40
10 1
10 2
10 3
2
2
3
5 30
1 1
2 2
4 4
8 8
16 16
4
1
2
3
4
2 2
2 2
1 1
1
2
6 5
1 96
2 100
2 97
3 95
4 98
5 99
2
1
2
*/
# | 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... |