fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,x;
  6. cin>>n>>x;
  7.  
  8. int arr[n+1],cost[n+1];
  9. pair <float, int > harga[n+1]; //cost number
  10.  
  11. harga[0]= make_pair(-9,-9);
  12.  
  13. for(int i=1;i<=n;i++)
  14. {
  15. cin>>arr[i];
  16. }
  17.  
  18. for(int i=1;i<=n;i++)
  19. {
  20. cin>>cost[i];
  21. double yo=cost[i];
  22. harga[i] = make_pair (yo/arr[i],i);
  23. }
  24.  
  25. sort(harga,harga+n+1);
  26.  
  27. int now=n;
  28. double pantek=0;
  29. while(true)
  30. {
  31.  
  32. if ( (now==0) or (x==0) )
  33. {
  34. break;
  35. }
  36.  
  37. if(x>=arr[harga[now].second])
  38. {
  39. pantek+= cost[harga[now].second];
  40. x-= arr[harga[now].second];
  41. }
  42. else
  43. {
  44. double tambah;
  45. tambah = x*harga[now].first;
  46. pantek+= tambah;
  47. x = 0;
  48. }
  49.  
  50. now--;
  51. }
  52.  
  53. cout<< fixed << setprecision(5)<< pantek<<"\n";
  54. return 0;
  55. }
Success #stdin #stdout 0s 4452KB
stdin
3 5
1 1 1
3 3 1
stdout
7.00000