Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<algorithm>
- using namespace std;
- typedef struct{
- double price;
- double quantity;
- double ppq;
- }rice;
- bool mycmp(rice a,rice b){
- return a.ppq < b.ppq;
- }
- int main()
- {
- int k;
- scanf("%d",&k);
- rice arrice[k];
- for(int i=0;i<k;i++){
- scanf("%lf %lf",&arrice[i].price,&arrice[i].quantity);
- arrice[i].ppq = arrice[i].price/arrice[i].quantity;
- }
- sort(arrice,arrice+k,mycmp);
- int m;
- scanf("%d",&m);
- int j = 0;
- for(int i=0;i<m;i++){
- double x;
- double ans = 0;
- scanf("%lf",&x);
- while(x > 0){
- if(arrice[j].quantity >= x){
- ans += arrice[j].ppq*x;
- arrice[j].quantity -= x;
- x = 0;
- }else{
- ans += arrice[j].ppq*arrice[j].quantity;
- x -= arrice[j].quantity;
- arrice[j].quantity = 0;
- }
- if(arrice[j].quantity == 0){
- j++;
- }
- }
- printf("%.3lf\n",ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment