이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Zadanie: Hiring
Autor: Tomasz Kwiatkowski
*/
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 7;
const int INF = 1e9 + 7;
struct frac
{
long long p, q;
frac () {}
frac (long long a, long long b = 1) : p(a), q(b) {}
bool operator==(frac x)
{
return p*x.q == q*x.p;
}
bool operator<=(frac x)
{
return p*x.q <= q*x.p;
}
bool operator<(frac x)
{
return p*x.q < q*x.p;
}
frac operator*(long long x)
{
return frac(p*x, q);
}
};
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
long long w;
cin >> n >> w;
vector<pair<frac, int>> sorted(n);
int i = 0;
for (auto& [x, ind] : sorted) {
cin >> x.p >> x.q;
ind = i++;
}
vector<pair<frac, int>> candidates(sorted);
sort(sorted.begin(), sorted.end(), [](auto lhs, auto rhs) {
if (lhs.fi == rhs.fi) {
if (lhs.fi.q == rhs.fi.q)
return lhs.se < lhs.se;
return lhs.fi.q < rhs.fi.q;
}
return rhs.fi < lhs.fi;
});
sort(candidates.begin(), candidates.end(), [](auto lhs, auto rhs) {
if (lhs.fi.q == rhs.fi.q)
return lhs.se < lhs.se;
return lhs.fi.q < rhs.fi.q;
});
vector<bool> ok(n, true);
int j = 0;
int cnt = 0;
frac money(w);
int k = 0;
long long sum_q = 0;
for (auto [x, ind] : sorted) {
if (ok[ind])
++cnt, sum_q += x.q;
ok[ind] = false;
while (j < n && (x*(sum_q + candidates[j].fi.q*ok[candidates[j].se]) <= frac(w))) {
sum_q += candidates[j].fi.q*ok[candidates[j].se];
cnt += ok[candidates[j].se];
ok[candidates[j].se] = false;
++j;
}
if (x*sum_q <= frac(w)) {
if (cnt > k)
k = cnt, money = x*sum_q;
else if (cnt == k && (x*sum_q < money))
money = x*sum_q;
}
sum_q -= x.q;
--cnt;
}
cout << k << '\n';
ok = vector<bool>(n, true);
vector<bool> chosen(n, false);
j = 0;
cnt = 0;
sum_q = 0;
for (auto [x, ind] : sorted) {
if (ok[ind])
++cnt, sum_q += x.q;
ok[ind] = false;
chosen[ind] = true;
while (j < n && (x*(sum_q + candidates[j].fi.q*ok[candidates[j].se]) <= frac(w))) {
chosen[candidates[j].se] = true;
sum_q += candidates[j].fi.q*ok[candidates[j].se];
cnt += ok[candidates[j].se];
ok[candidates[j].se] = false;
++j;
}
if (x*sum_q <= frac(w) && cnt == k && (x*sum_q == money)) {
for (int i = 0; i < n; ++i)
if (chosen[i])
cout << i + 1 << '\n';
return 0;
}
sum_q -= x.q;
chosen[ind] = false;
--cnt;
}
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... |