Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- using namespace std;
- typedef struct rice{
- double price;
- int qt;
- bool operator < (const rice &rhs)const{
- return price > rhs.price;
- }
- }rice;
- priority_queue<rice> pile;
- int np, nm;
- int main(){
- double p, sum;
- int q, want;
- scanf("%d", &np);
- for(int i = 0; i < np; ++i){
- scanf("%lf %d", &p, &q);
- pile.push({p / (double)q, q});
- }
- scanf("%d", &nm);
- for(int i = 0; i < nm; ++i){
- scanf("%d", &want);
- sum = 0;
- while(!pile.empty() && want > 0){
- p = pile.top().price;
- q = pile.top().qt;
- if(want < q){
- sum += p * want;
- pile.push({p, q - want});
- pile.pop();
- want -= q;
- } else {
- sum += p * q;
- want -= q;
- pile.pop();
- }
- }
- printf("%.3f\n", sum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement