이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
struct node{
double Q;
double P;
double U;
int id;
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long N, W;
double H = 0, BP = 0;
cin >> N >> W;
vector<node> arr(N);
for(int i = 0; i < N; i ++){
cin >> arr[i].P >> arr[i].Q;
arr[i].U = arr[i].P/arr[i].Q;
arr[i].id = i + 1;
}
sort(arr.begin(), arr.end(), [&](node a, node b){return a.U < b.U;});
priority_queue<pair<double, int>> que;
bitset<500500> in;
double qual = 0, id = 0;
for(int i = 0; i < N; i ++){
qual += arr[i].Q;
que.push({arr[i].Q, arr[i].id});
while(qual * arr[i].U > W){
qual -= que.top().first;
que.pop();
}
if(que.size() > H){
H = que.size();
BP = qual * arr[i].U;
id = i + 1;
}
else if(que.size() == H && BP > qual * arr[i].U){
BP = qual * arr[i].U;
id = i + 1;
}
}
while(!que.empty())que.pop();
qual = 0;
for(int i = 0; i < id; i ++){
qual += arr[i].Q;
que.push({arr[i].Q, arr[i].id});
in[arr[i].id] = 1;
while(qual * arr[i].U > W){
qual -= que.top().first;
in[que.top().second] = 0;
que.pop();
}
}
cout << H << endl;
for(int i = 0; i < N+1; i ++){
if(in[i])
cout << i << endl;
}
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... |