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 MOD 998244353
using namespace std;
bool compare(pair<pair<long long, long long>, int>a, pair<pair<long long, long long>, int>b)
{
if(a.first.first*b.first.second != a.first.second*b.first.first)
return a.first.first*b.first.second < a.first.second*b.first.first;
return a.first.first < b.first.first;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
long long n, w;
cin >> n >> w;
vector<pair<pair<long long, long long>, int> >v;
for(int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
v.push_back(make_pair(make_pair(x, y), i));
}
sort(v.begin(), v.end(), compare);
priority_queue<pair<int, int> >pq;
long long sum=0;
long long ma=0, idx=0, ma_v_s=0, ma_v_q=0;
for(int i = 0; i < n; i++)
{
sum+=v[i].first.second;
pq.push(make_pair(v[i].first.second, v[i].second));
while(sum*v[i].first.first > w*v[i].first.second && !pq.empty())
{
sum-=pq.top().first;
pq.pop();
}
if(pq.size() > ma)
{
ma=pq.size();
idx=i;
ma_v_s=v[i].first.first*sum;
ma_v_q=v[i].first.second;
}
else if(pq.size() == ma && ma_v_s*v[i].first.second > ma_v_q*v[i].first.first*sum)
{
idx=i;
ma_v_s=v[i].first.first*sum;
ma_v_q=v[i].first.second;
}
}
while(!pq.empty())
pq.pop();
sum=0;
for(int i = 0; i <= idx; i++)
{
sum+=v[i].first.second;
pq.push(make_pair(v[i].first.second, v[i].second));
while(sum*v[i].first.first > w*v[i].first.second && !pq.empty())
{
sum-=pq.top().first;
pq.pop();
}
}
cout << ma;
while(!pq.empty())
{
cout << '\n' << pq.top().second+1;
pq.pop();
}
}
Compilation message (stderr)
hiring.cpp: In function 'int main()':
hiring.cpp:38:16: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
38 | if(pq.size() > ma)
| ~~~~~~~~~~^~~~
hiring.cpp:45:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
45 | else if(pq.size() == ma && ma_v_s*v[i].first.second > ma_v_q*v[i].first.first*sum)
| ~~~~~~~~~~^~~~~
# | 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... |