이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct T{
int sum,cnt;
}st[80001];
int n,s[500001],q[500001],a[500001],w,res,num,den,pos;
void update(int node, int l, int r, int i){
if (l>i||r<i)
return;
if (l==r){
st[node].sum+=l;
st[node].cnt++;
return;
}
int mid=(l+r)>>1;
update(node<<1,l,mid,i);
update(node<<1|1,mid+1,r,i);
st[node].sum=st[node<<1].sum+st[node<<1|1].sum;
st[node].cnt=st[node<<1].cnt+st[node<<1|1].cnt;
}
pair <int, int> get(int node, int l, int r, int val){
if (l==r){
int x=min(val/l,st[node].cnt);
return {x,l*x};
}
int mid=(l+r)>>1;
if (st[node<<1].sum<val){
auto [x,y]=get(node<<1|1,mid+1,r,val-st[node<<1].sum);
x+=st[node<<1].cnt;
y+=st[node<<1].sum;
return {x,y};
}
return get(node<<1,l,mid,val);
}
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> w;
for (int i=1;i<=n;i++)
cin >> s[i] >> q[i];
iota(a,a+n+1,0);
sort(a+1,a+n+1,[](int i, int j){return s[i]*q[j]<s[j]*q[i];});
for (int j=1;j<=n;j++){
int i=a[j];
int lim=w*q[i]/s[i]-q[i];
if (lim>=0){
auto [x,y]=get(1,1,20000,lim);
x++;
y=(y+q[i])*s[i];
if (res<x||(res==x&&y*den<num*q[i])){
res=x;
num=y;
den=q[i];
pos=j;
}
}
update(1,1,20000,q[i]);
}
cout << res << '\n';
int j=a[pos],lim=w*q[j]/s[j]-q[j];
sort(a+1,a+pos,[](int i, int j){return q[i]<q[j];});
for (int i=1;i<pos;i++){
lim-=q[a[i]];
if (lim<0)
break;
cout << a[i] << '\n';
}
cout << j << '\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... |