Submission #785723

#TimeUsernameProblemLanguageResultExecution timeMemory
785723canadavid1Hiring (IOI09_hiring)C++14
2 / 100
1590 ms12312 KiB
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; #define all(x) begin(x),end(x) #define rep(var,e) for(int var = 0; var < e; var++) struct Rational { int num; int den; Rational() {} Rational(int n, int d=1) : num(n), den(d) {} Rational operator*(Rational other) {return Rational(num*other.num,den*other.den);} Rational inv() {return Rational(den,num);} Rational operator/(Rational other) {return *this * (other.inv());} Rational operator+(Rational other) {return Rational(num*other.den + other.num * den,den*other.den);} Rational neg() {return Rational(-num,den);} Rational operator-(Rational other) {return *this + (other.neg());} Rational operator+=(Rational other) {*this = *this + other;return *this;} const bool operator<(const Rational& other) const { return ((i64)num) * ((i64)other.den) < ((i64)other.num) * ((i64)den); } const bool operator>(const Rational& other) const { return other < *this; } }; struct worker { int mincost,skill,num; const bool operator<(const worker& other) const { return skill < other.skill; } }; signed main() { int N,W; cin >> N >> W; vector<worker> workers(N); rep(i,N) { cin >> workers[i].mincost >> workers[i].skill; workers[i].num = i+1; } // one of the included workers is paid their minimum // for each, add the cheapest workers until can't anymore // sort all workers by min_cost sort(all(workers)); vector<int> included_workers; Rational p(0); rep(i,N) // index in workers { worker& s = workers[i]; Rational costperskill = Rational(s.mincost,s.skill); Rational cc = 0; vector<int> included; for(auto & j : workers) { Rational pay = costperskill * j.skill; if(pay + cc > W) break; if(pay < j.mincost) continue; included.push_back(j.num); cc += pay; } if (included.size() > included_workers.size() || (included.size() == included_workers.size() && cc < p)) { swap(included,included_workers); // O(1) assign, unneccesary p = cc; continue; } } sort(all(included_workers)); cout << included_workers.size() << "\n"; for(auto i : included_workers) cout << i << "\n"; }
#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...