DontCallMeNuttoPleas

Rice

Mar 26th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using pii=pair<double,double>;
  4. int main(){
  5.     int n,x,y,w;
  6.     double ppq,price,p,q;
  7.     scanf("%d",&n);
  8.     priority_queue<pii,vector<pii>,greater<pii>> pq;
  9.    
  10.     for(int i=0;i<n;i++){
  11.         scanf("%lf%lf",&p,&q);
  12.         ppq=p/q;
  13.         pq.push({ppq,q});
  14.     }
  15.    
  16.     scanf("%d",&n);
  17.     for(int i=0;i<n;i++){
  18.         price=0;
  19.         scanf("%d",&w);
  20.         while(w!=0){
  21.             double P=pq.top().first;
  22.             double Q=pq.top().second;
  23.             pq.pop();
  24.             if(Q>=w){
  25.                 Q=Q-w;
  26.                 price+=P*w;
  27.                 if(Q!=0)
  28.                 pq.push({P,Q});
  29.                 break;
  30.             }else{
  31.                 price+=P*Q;
  32.                 w-=Q;
  33.             }
  34.         }
  35.         printf("%.3lf\n",price);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment