이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |