이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, W, sum, rst;
double psum = 1e18;
pair<pair<ll, ll>, int> D[500005];
pair<pair<ll, ll>, int> max_k;
priority_queue<pair<pair<ll, ll>, int>> pq;
bool cmp(pair<pair<ll, ll>, int> a, pair<pair<ll, ll>, int> b) {
pair<ll, ll> x = a.first, y = b.first;
return x.first * y.second > y.first * x.second;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> W;
for (int i = 0; i < N; i++) {
int q, s;
cin >> s >> q;
D[i] = {{q, s}, i};
}
sort(D, D+N, cmp);
for (int i = 0; i < N; i++) {
pair<ll, ll> E = D[i].first;
ll Q = E.first, S = E.second;
pq.push(D[i]);
sum += Q;
while ((double)sum/Q*S > W && !pq.empty()) {
sum -= pq.top().first.first;
pq.pop();
}
if (rst < (ll)pq.size()) {
rst = pq.size();
psum = (double)sum*S/Q;
max_k = D[i];
} else if (rst == (ll)pq.size()) {
if ((double)sum/Q*S < psum) {
psum = (double)sum*S/Q;
max_k = D[i];
}
}
}
sum = 0;
ll Qr = max_k.first.first, Sr = max_k.first.second, im = max_k.second;
if (rst == 0) {
cout << 0 <<endl;
return 0;
}
while(!pq.empty()) pq.pop();
for (int i = 0; i < N; i++) {
pair<ll, ll> E = D[i].first;
ll Q = E.first, S = E.second;
pq.push(D[i]);
sum += Q;
while ((double)sum/Q*S > W && !pq.empty()) {
sum -= pq.top().first.first;
pq.pop();
}
if (i == im) {
cout << pq.size() << '\n';
while (!pq.empty()) {
cout << pq.top().second + 1 << '\n';
pq.pop();
}
break;
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'int main()':
hiring.cpp:49:8: warning: unused variable 'Qr' [-Wunused-variable]
49 | ll Qr = max_k.first.first, Sr = max_k.first.second, im = max_k.second;
| ^~
hiring.cpp:49:32: warning: unused variable 'Sr' [-Wunused-variable]
49 | ll Qr = max_k.first.first, Sr = max_k.first.second, im = max_k.second;
| ^~
# | 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... |