Submission #785727

#TimeUsernameProblemLanguageResultExecution timeMemory
785727canadavid1Hiring (IOI09_hiring)C++14
64 / 100
1579 ms8940 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++)

using Rational = double;
/*
int gcd(int a, int b)
{
    if(a < b) swap(a,b);
    if(b==0) return a;
    if(b==1) return 1;
    return gcd(a-b,b);
}


struct Rational
{
    int num;
    int den;
    void reduce()
    {
        int a = gcd(abs(num),abs(den));
        num /= a;
        den /= a;
    }
    Rational() {}
    Rational(int n, int d=1) : num(n), den(d) {reduce();}
    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)/Rational(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...