이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
signed main(){
long long n,w;
cin>>n>>w;
vector<pair<double,pair<double,int>>> v;
for(int i = 0;i<n;i++){
double s,q;cin>>s>>q;
v.push_back({s/q,{q,i+1}});
}
sort(v.begin(),v.end());
priority_queue<pair<double,int>> q,p;
double sum = 0;
int ma = 0,ind;
for(int i = 0;i<v.size();i++){
p.push({-v[i].second.first,v[i].second.second});
sum+=(-p.top().first);
q.push({-p.top().first,p.top().second});
p.pop();
double no =sum*v[i].first;
if(no>w){
pair<double,int>pa = q.top();
q.pop();
sum-=pa.first;
p.push({-pa.first,pa.second});
}
if(q.size()>ma){
ma=q.size();
ind = i;
}
}
while(!q.empty())q.pop();
while(!p.empty())p.pop();
sum=0;
for(int i = 0;i<=ind;i++){
p.push({-v[i].second.first,v[i].second.second});
sum+=(-p.top().first);
q.push({-p.top().first,p.top().second});
p.pop();
double no =sum*v[i].first;
if(no>w){
pair<double,int>pa = q.top();
q.pop();
sum-=pa.first;
p.push({-pa.first,pa.second});
}
}
cout<<q.size()<<endl;
while(q.size()){
cout<<q.top().second<<"\n";
q.pop();
}
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'int main()':
hiring.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<double, std::pair<double, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i = 0;i<v.size();i++){
| ~^~~~~~~~~
hiring.cpp:30:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<double, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | if(q.size()>ma){
| ~~~~~~~~^~~
hiring.cpp:38:20: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
38 | for(int i = 0;i<=ind;i++){
| ~^~~~~
# | 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... |