Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pii=pair<double,double>;
- int main(){
- int n,x,y,w;
- double ppq,price,p,q;
- scanf("%d",&n);
- priority_queue<pii,vector<pii>,greater<pii>> pq;
- for(int i=0;i<n;i++){
- scanf("%lf%lf",&p,&q);
- ppq=p/q;
- pq.push({ppq,q});
- }
- scanf("%d",&n);
- for(int i=0;i<n;i++){
- price=0;
- scanf("%d",&w);
- while(w!=0){
- double P=pq.top().first;
- double Q=pq.top().second;
- pq.pop();
- if(Q>=w){
- Q=Q-w;
- price+=P*w;
- if(Q!=0)
- pq.push({P,Q});
- break;
- }else{
- price+=P*Q;
- w-=Q;
- }
- }
- printf("%.3lf\n",price);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment