Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int fn(const void *a,const void *b)
- {
- double *aa=(double *)a;
- double *bb=(double *)b;
- if(aa[1]>bb[1]) return 1;
- else return -1;
- }
- int main()
- {
- double priceavg[100000][2],total;
- int i,k,m,p,price,kg,start=0;
- scanf("%d",&k);
- for(i=0;i<k;i++)
- {
- scanf("%lf%d",&priceavg[i][0],&price);
- priceavg[i][1]=priceavg[i][0]/price;
- }
- qsort(priceavg,k,sizeof(priceavg[0]),fn);
- /*printf("------------------\n\n");
- for(i=0;i<k;i++) printf("%lf %lf\n",priceavg[i][0],priceavg[i][1]);*/
- scanf("%d",&m);
- for(i=0;i<m;i++)
- {
- scanf("%d",&kg);
- total=0;
- if(priceavg[start][0]!=0)
- {
- if(kg<priceavg[start][0])
- {
- printf("%lf",priceavg[start][1]*kg);
- priceavg[start][0]-=kg;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement