이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define val first
#define id second
#define pii pair<ll, ll>
typedef long long ll;
const ll MOD = 1000000007LL;
const ll INF = 1e15;
using namespace std;
struct worker {
ll s, q, id;
};
ll n, w, sum;
pair<ll, long double> ans;
worker a[500010];
priority_queue<pii> q;
long double f(worker x) {
return x.s*1.0/x.q;
}
int main() {
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(0);
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> a[i].s >> a[i].q;
a[i].id = i;
}
sort(a+1, a+n+1, [&](worker x, worker y) -> bool {
return f(x) < f(y);
});
sum = 0; ans = {0, 0};
while (!q.empty()) q.pop();
for (int i = 1; i <= n; i++) {
q.push({a[i].q, a[i].id});
sum += a[i].q;
while (!q.empty() && f(a[i])*sum > w) {
sum -= q.top().val;
q.pop();
}
ans = max(ans, {(ll)q.size(), sum*f(a[i])});
}
if (ans.first == 0) {
cout << "0\n";
return 0;
}
sum = 0;
while (!q.empty()) q.pop();
for (int i = 1; i <= n; i++) {
q.push({a[i].q, a[i].id});
sum += a[i].q;
while (!q.empty() && f(a[i])*sum > w) {
sum -= q.top().val;
q.pop();
}
if (ans.first == (ll)q.size() && ans.second == sum*f(a[i])) {
cout << ans.first << "\n";
while (!q.empty()) {
cout << q.top().id << "\n";
q.pop();
}
return 0;
}
}
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... |