Submission #228675

#TimeUsernameProblemLanguageResultExecution timeMemory
228675osaaateiasavtnlHiring (IOI09_hiring)C++14
50 / 100
1591 ms12264 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 5e5 + 7;
int n, W;
struct Chel {
    int s, q, i;
} a[N];  
bool comp(Chel a, Chel b) {
    //return (a.s/a.q) < (b.s/b.q);
    return a.s * b.q < b.s * a.q;
}   
bool compq(int i, int j) {
    return a[i].q < a[j].q;
}   
bool ls(ii a, ii b) {
    return a.f * b.s < b.f * a.s;
}
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> W;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].s >> a[i].q;
        a[i].i = i;
    }   
    sort(a, a + n, comp);
    vector <int> cur;

    int ans = 0;
    ii pay = {0, 1};

    vector <int> who;

    for (int i = 0; i < n; ++i) {
        cur.app(i);
        sort(all(cur), compq);

        int sum = 0;
        for (int j = 0; j < cur.size(); ++j) {
            sum += a[cur[j]].q;
            if (sum * a[i].s <= W * a[i].q) {
                ii np = mp(sum * a[i].s, a[i].q);
                if (j + 1 > ans || (j + 1 == ans && ls(np, pay))) {
                    ans = j + 1;
                    pay = np;
                    who = {};
                    for (int k = 0; k <= j; ++k) {
                        who.app(a[cur[k]].i);
                    }   
                }
            }   
        }   
    }   
    cout << ans << endl;
    for (int e : who)
        cout << e + 1 << ' ';
    cout << endl;
}

Compilation message (stderr)

hiring.cpp: In function 'int main()':
hiring.cpp:53:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < cur.size(); ++j) {
                         ~~^~~~~~~~~~~~
#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...