이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
using i64 = int64_t;
using f64 = double;
struct Candidate {
i64 id;
i64 s;
i64 q;
};
int main() {
i64 n, w;
std::cin >> n >> w;
std::vector<Candidate> candidates;
for (i64 i = 0; i < n; i++) {
i64 s, q;
std::cin >> s >> q;
candidates.push_back({ .id = i, .s = s, .q = q });
}
std::sort(candidates.begin(), candidates.end(), [](const auto &lhs, const auto &rhs) {
return lhs.s * rhs.q < rhs.s * lhs.q;
});
std::vector<i64> best_bin;
double best_budget = -1;
for (i64 i = 0; i < n; i++) {
auto model = candidates[i];
auto s_over_q = (f64)model.s / (f64)model.q;
double budget = w;
std::vector<i64> bin;
for (i64 j = 0; j < n; j++) {
const auto &candidate = candidates[j];
double price = s_over_q * candidate.q;
if (price + 0.000001 >= candidate.s && price <= budget) {
budget -= price;
bin.push_back(j);
}
}
if (bin.size() > best_bin.size() || (bin.size() == best_bin.size() && budget > best_budget)) {
best_bin = std::move(bin);
best_budget = budget;
}
}
std::cout << best_bin.size() << '\n';
for (i64 x : best_bin)
std::cout << candidates[x].id + 1 << '\n';
}
# | 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... |