이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define debug(x) cerr << " " << x << " " << #x << endl;
int main(){
long long nb,w;
cin>>nb>>w;
vector<pair<long double,long long>>g;
vector<long long>k1,k2;
for (long long i = 0; i < nb; ++i)
{
long double s,q;
cin>>s>>q;
g.pb({s/q,i});
k1.pb(s);
k2.pb(q);
}
sort(all(g));
priority_queue<pair<long double,long long>>g2;
long double cur=0;
pair<pair<long long,long long>,int> ans={{0,0},0};
for (long long i = 0; i < nb; ++i)
{
g2.push({k2[g[i].second],i});
if(i){
cur/=(g[i-1].first);
}
cur*=g[i].first;
cur+=k1[g[i].second];
while(!(g2.empty()) && cur>w){
cur-=((g2.top().first)*g[i].first);
g2.pop();
}
ans=max(ans,{{(long long)(g2.size()),-cur},i});
}
cout<<ans.first.first<<'\n';
while(!(g2.empty()))
{
g2.pop();
}
cur=0;
for (long long i = 0; i <= ans.second; ++i)
{
g2.push({k2[g[i].second],i});
if(i){
cur/=(g[i-1].first);
}
cur*=g[i].first;
cur+=k1[g[i].second];
while(!(g2.empty()) && cur>w){
cur-=((g2.top().first)*g[i].first);
g2.pop();
}
}
while(!(g2.empty()))
{
cout<<g[g2.top().second].second+1;
g2.pop();
if(g2.size())cout<<'\n';
}
return 0;
}
# | 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... |