이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define int long long
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
signed main() {
io; int n, w;
cin >> n >> w;
double s[n], q[n];
for (int i = 0; i < n; i++) {
cin >> s[i] >> q[i];
}
double cost;
double ans;
vector<double> fiine;
vector<double> fiine2;
double global_max = 0;
double temp = 0;
multiset<pair<double,int>> v;
for (int i = 0; i < n; i++) {
cost = s[i];
ans = 1;
v.clear();
fiine.clear();
fiine.push_back(i+1);
// set i as being paid s[i] and take it by default
for (int j = 0; j < n; j++) {
if (i == j) continue;
temp = (q[j]/q[i])*s[i];
if (temp >= s[j]) v.insert({temp,j+1});
}
for (auto e: v) {
if (cost+e.first <= w) {
ans++;
cost += e.first;
fiine.push_back(e.second);
// cerr << "pushing back " << e.second << nl;
} else break;
}
global_max = max(global_max, ans);
if (global_max == ans) {
fiine2 = fiine;
// cerr << "hi i am here "<< nl;
}
}
cout << global_max << nl;
for (int i = 0; i < global_max; i++) cout << fiine2[i] << nl;
}
/*
fix a c (double) that each person is paid times their qual
cost must be more than or equal to c times sum of qualifications
maintain pq sorted people you can use in increasing q
increase value of c, add more to pq
once sum of everyone in pq exceeds how much you can use, pop max qual out
c is some value of sk/qk
*/
# | 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... |