Submission #507582

#TimeUsernameProblemLanguageResultExecution timeMemory
507582tabrHiring (IOI09_hiring)C++17
94 / 100
856 ms33384 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n; long long w; cin >> n >> w; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { auto x = a[i]; auto y = a[j]; if (x.first * y.second != x.second * y.first) { return x.first * y.second < x.second * y.first; } return x.first < y.first; }); multiset<pair<int, int>> st; int sum = 0; pair<int, long double> ans = make_pair(0, 0); for (int i : order) { sum += a[i].second; st.emplace(a[i].second, i); while (sum * 1LL * a[i].first > w * a[i].second) { auto it = prev(st.end()); sum -= it->first; st.erase(it); } ans = max(ans, make_pair((int) st.size(), -1.0L * sum * a[i].first / a[i].second)); } if (ans.first == 0) { cout << 0 << '\n'; return 0; } st.clear(); sum = 0; for (int i : order) { sum += a[i].second; st.emplace(a[i].second, i); while (sum * 1LL * a[i].first > w * a[i].second) { auto it = prev(st.end()); sum -= it->first; st.erase(it); } if (make_pair((int) st.size(), -1.0L * sum * a[i].first / a[i].second) == ans) { cout << ans.first << '\n'; for (auto p : st) { cout << p.second + 1 << '\n'; } break; } } return 0; }
#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...