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;
}
sort(a.begin(), a.end(), [&](auto x, auto y) {
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;
int ans = 0;
for (int i = 0; i < n; i++) {
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, (int) st.size());
}
st.clear();
sum = 0;
for (int i = 0; i < n; i++) {
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 ((int) st.size() == ans) {
cout << ans << '\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... |