Submission #297647

#TimeUsernameProblemLanguageResultExecution timeMemory
297647hhh07Hiring (IOI09_hiring)C++14
99 / 100
997 ms39080 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#include <cstring>

using namespace std;

typedef long long ll;
typedef pair<double, double> ii;
typedef pair<ii, ii> iiii;

vector<vector<int>> adjList;

int main(){
    ios_base::sync_with_stdio(false);
    double n, w;
    cin >> n >> w;
    vector<iiii> c; double s, q;
    for (int i = 0; i < n; i++){
        cin >> s >> q;
        c.push_back({{s/q, i}, {s, q}});
    }
    
    sort(c.begin(), c.end());
    int maxi = 0, cost = 0, idx;
    double uk = 0; priority_queue<double> pq;
    for (int i = 0; i < n; i++){
        pq.push(c[i].second.second);
        uk += c[i].second.second;
        double maks = w/c[i].first.first;
        while(uk > maks){
            uk -= pq.top();
            pq.pop();
        }
        int cijena = uk*c[i].first.first;
        if (pq.size() > maxi || (pq.size() == maxi && cijena < cost)){
            maxi = pq.size();
            cost = cijena;
            idx = i;
        }
    }
    priority_queue<ii> ans; uk = 0;
    for (int i = 0; i <= idx; i++){
        ans.push({c[i].second.second, c[i].first.second});
        uk += c[i].second.second;
    }
    double maks = w/c[idx].first.first;
    
    while(uk > maks){
        uk -= ans.top().first;
        ans.pop();
    }
    vector<int> x;
    while(!ans.empty()){
        x.push_back(ans.top().second);
        ans.pop();
    }
    cout << x.size() << endl;
    for (int i = 0; i < x.size(); i++){
        cout << x[i] + 1 << endl;
    }
    return 0;
}

Compilation message (stderr)

hiring.cpp: In function 'int main()':
hiring.cpp:38:23: warning: comparison of integer expressions of different signedness: 'std::priority_queue<double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if (pq.size() > maxi || (pq.size() == maxi && cijena < cost)){
      |             ~~~~~~~~~~^~~~~~
hiring.cpp:38:44: warning: comparison of integer expressions of different signedness: 'std::priority_queue<double>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if (pq.size() > maxi || (pq.size() == maxi && cijena < cost)){
      |                                  ~~~~~~~~~~^~~~~~~
hiring.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i = 0; i < x.size(); i++){
      |                     ~~^~~~~~~~~~
hiring.cpp:45:23: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     for (int i = 0; i <= idx; i++){
      |                     ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...