이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
bool compare(pair<int, int>a, pair<int, int>b)
{
return a.first*b.second < a.second*b.first;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
long long n, w;
cin >> n >> w;
vector<pair<long long, long long> >v;
for(int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
}
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].second;
pq.push(make_pair(v[i].second, i));
while(sum*v[i].first > w*v[i].second && !pq.empty())
{
sum-=pq.top().first;
pq.pop();
}
if(pq.size() > ma)
{
ma=pq.size();
idx=i;
ma_v_s=v[i].first*sum;
ma_v_q=v[i].second;
}
else if(pq.size() == ma && ma_v_s*v[i].second > ma_v_q*v[i].first*sum)
{
idx=i;
ma_v_s=v[i].first*sum;
ma_v_q=v[i].second;
}
}
while(!pq.empty())
pq.pop();
sum=0;
for(int i = 0; i <= idx; i++)
{
sum+=v[i].second;
pq.push(make_pair(v[i].second, i));
while(sum*v[i].first > w*v[i].second && !!pq.empty())
{
sum-=pq.top().first;
pq.pop();
}
}
cout << ma << '\n';
while(!pq.empty())
{
cout << pq.top().second+1 << '\n';
pq.pop();
}
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'int main()':
hiring.cpp:36: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]
36 | if(pq.size() > ma)
| ~~~~~~~~~~^~~~
hiring.cpp:43: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]
43 | else if(pq.size() == ma && ma_v_s*v[i].second > ma_v_q*v[i].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... |