This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
long long 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |