이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
double w;
cin >> n >> w;
vector <pair<pair<double,int>,pair<double,double>>> c(n);
for (int i = 0; i < n; i++){
double p, q;
cin >> p >> q;
c[i] = make_pair(make_pair(p/q,i+1),make_pair(p,q));
}
sort(c.begin(),c.end());
double totq = 0;
priority_queue<double> kju;
int najs = 0, ind;
double najcijena = 1000000000;
for (int i = 0; i < n; i++){
kju.push(c[i].second.second);
totq += c[i].second.second;
double gran = w / c[i].first.first;
while (totq > gran){
totq -= kju.top();
kju.pop();
}
double cijena = totq*c[i].first.first;
if (kju.size() > najs || (kju.size() == najs && najcijena > cijena)){
najs = kju.size();
ind = i;
najcijena = cijena;
}
}
totq = 0;
priority_queue<pair<double,int>> kju2;
for (int i = 0; i <= ind; i++){
kju2.push(make_pair(c[i].second.second,c[i].first.second));
totq += c[i].second.second;
}
double gran = w / c[ind].first.first;
while (totq > gran){
totq -= kju2.top().first;
kju2.pop();
}
cout << kju2.size() << endl;
vector <int> rjesenje;
while (!kju2.empty()){
rjesenje.push_back(kju2.top().second);
kju2.pop();
}
sort(rjesenje.begin(),rjesenje.end());
for (int i = 0; i < rjesenje.size(); i++)
cout << rjesenje[i] << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'int main()':
hiring.cpp:35:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
35 | if (kju.size() > najs || (kju.size() == najs && najcijena > cijena)){
| ~~~~~~~~~~~^~~~~~
hiring.cpp:35:42: warning: comparison of integer expressions of different signedness: 'std::priority_queue<double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
35 | if (kju.size() > najs || (kju.size() == najs && najcijena > cijena)){
| ~~~~~~~~~~~^~~~~~~
hiring.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i < rjesenje.size(); i++)
| ~~^~~~~~~~~~~~~~~~~
hiring.cpp:43:21: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
43 | 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... |