이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N;
vector<pair<pair<long long int,long long int>,int>> v;
long long int W;
long long int h1,h2;
priority_queue<pair<long long int,int>,vector<pair<long long int,int>>,greater<pair<long long int,int>>> satprime;
priority_queue<pair<long long int,int>> sat;
vector<pair<pair<long long int, long long int>,int>> nov;
bool c(pair<pair<long long int, long long int>,int> ii1, pair<pair<long long int, long long int>,int> ii2){
return ii1.first.first * ii2.first.second < ii2.first.first * ii1.first.second;
}
int main(){
scanf(" %d",&N);
scanf(" %lld",&W);
for(int i = 0; i < N; i++){
scanf(" %lld",&h1);
scanf(" %lld",&h2);
v.push_back({{h1,h2},i});
}
sort(v.begin(),v.end(),c);
long long int sum = 0;
int ans = 0;
for(int i = 0; i < N; i++){
if( (sum + v[i].first.second) * v[i].first.first <= W * v[i].first.second){
while(!satprime.empty() && (satprime.top().first + sum + v[i].first.second) * v[i].first.first <= W * v[i].first.second ){
sum += satprime.top().first;
sat.push(satprime.top());
satprime.pop();
}
if(ans == sat.size() + 1){
nov.push_back({{ (sum + v[i].first.second) * v[i].first.first,v[i].first.second }, i});
}
else{
nov.clear();
nov.push_back({{ (sum + v[i].first.second) * v[i].first.first,v[i].first.second },i});
}
ans = sat.size() + 1;
}
if(!sat.empty() && v[i].first.second < sat.top().first){
pair<long long int,int> h = sat.top();
satprime.push(h);
sat.push({v[i].first.second,v[i].second});
sum -= h.first;
sum += v[i].first.second;
}
else{
satprime.push({v[i].first.second,v[i].second});
}
}
printf("%d\n",ans);
sort(nov.begin(),nov.end(),c);
int j = nov[0].second;
while(!sat.empty()){
sat.pop();
}
while(!satprime.empty()){
satprime.pop();
}
sum = 0;
for(int i = 0; i < N; i++){
if( (sum + v[i].first.second) * v[i].first.first <= W * v[i].first.second){
while(!satprime.empty() && (satprime.top().first + sum + v[i].first.second) * v[i].first.first <= W * v[i].first.second ){
sum += satprime.top().first;
sat.push(satprime.top());
satprime.pop();
}
}
if(i == j){
sat.push({v[i].first.second,v[i].second});
break;
}
if(!sat.empty() && v[i].first.second < sat.top().first){
pair<long long int,int> h = sat.top();
satprime.push(h);
sat.push({v[i].first.second,v[i].second});
sum -= h.first;
sum += v[i].first.second;
}
else{
satprime.push({v[i].first.second,v[i].second});
}
}
while(!sat.empty()){
printf("%d\n",sat.top().second + 1);
sat.pop();
}
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'int main()':
hiring.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(ans == sat.size() + 1){
| ~~~~^~~~~~~~~~~~~~~~~
hiring.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
hiring.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf(" %lld",&W);
| ~~~~~^~~~~~~~~~~~
hiring.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf(" %lld",&h1);
| ~~~~~^~~~~~~~~~~~~
hiring.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf(" %lld",&h2);
| ~~~~~^~~~~~~~~~~~~
# | 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... |