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 <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ll long long
using ld = long double;
ll n, w;
struct worker
{
int s, q, i;
} a[1<<19];
set<pair<ll, int>> st;
pair<int, ld> opt = {0, -1e18};
ll opt_i, cur;
void add(ll i)
{
cur += a[i].q;
st.emplace(a[i].q, i);
}
void del()
{
auto it = prev(st.end());
cur -= it->first;
st.erase(it);
}
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> w;
for (int i = 1; i <= n; ++i) cin >> a[i].s >> a[i].q, a[i].i = i;
sort(a+1, a+1+n, [](const worker &a, const worker &b){
return ld(a.s)/ld(a.q) < ld(b.s)/ld(b.q);
});
for (int i = 1; i <= n; ++i)
{
ld u = ld(a[i].s)/ld(a[i].q);
add(i);
while (cur * u > w) del();
pair<int, ld> c2 = {st.size(), -cur * u};
if (c2 > opt) opt = c2, opt_i = i;
//cout << " " << i << " " << st.size() << " " << u << " " << cur << '\n';
}
st.clear();
cur = 0;
for (int i = 1; i <= opt_i; ++i)
{
ld u = ld(a[i].s)/ld(a[i].q);
add(i);
while (cur * u > w) del();
}
cout << st.size() << '\n';
for (auto [u, v] : st) cout << a[v].i << '\n';
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... |