Advertisement
nontawat1996

Untitled

Mar 4th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int fn(const void *a,const void *b)
  5. {
  6. double *aa=(double *)a;
  7. double *bb=(double *)b;
  8. if(aa[1]>bb[1]) return 1;
  9. else return -1;
  10. }
  11. int main()
  12. {
  13. double priceavg[100000][2],total;
  14. int i,k,m,p,price,kg,start=0;
  15. scanf("%d",&k);
  16. for(i=0;i<k;i++)
  17. {
  18. scanf("%lf%d",&priceavg[i][0],&price);
  19. priceavg[i][1]=priceavg[i][0]/price;
  20. }
  21. qsort(priceavg,k,sizeof(priceavg[0]),fn);
  22. /*printf("------------------\n\n");
  23. for(i=0;i<k;i++) printf("%lf %lf\n",priceavg[i][0],priceavg[i][1]);*/
  24. scanf("%d",&m);
  25. for(i=0;i<m;i++)
  26. {
  27. scanf("%d",&kg);
  28. total=0;
  29. if(priceavg[start][0]!=0)
  30. {
  31. if(kg<priceavg[start][0])
  32. {
  33. printf("%lf",priceavg[start][1]*kg);
  34. priceavg[start][0]-=kg;
  35. }
  36. }
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement