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 <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;
}
Compilation message (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... |