제출 #297152

#제출 시각아이디문제언어결과실행 시간메모리
297152Harry464Hiring (IOI09_hiring)C++14
100 / 100
1035 ms32600 KiB
#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 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...