Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct mal
- {
- int price;
- int weight;
- };
- bool cmp(struct mal a, struct mal b)
- {
- double unitprice1 = (double)a.price / a.weight;
- double unitprice2 = (double)b.price / b.weight;
- return unitprice1 > unitprice2;
- }
- double buijjhalow(struct mal mals[],int bostarWeight, int n)
- {
- sort(mals, mals + n, cmp);
- int w = 0;
- double res = 0.0;
- for (int i = 0; i < n; i++)
- {
- if (w + mals[i].weight <= bostarWeight)
- {
- w += mals[i].weight;
- res += mals[i].price;
- }
- else
- {
- int left = bostarWeight - w;
- res += mals[i].price * ((double) left / mals[i].weight);
- break;
- }
- }
- return res;
- }
- int main()
- {
- int a,n,c;
- cin>>n>>c;
- mal mals[n];
- for(int i=0;i<n;i++){
- cin>>a;
- mals[i].weight=a;
- }
- for(int i=0;i<n;i++){
- cin>>a;
- mals[i].price=a;
- }
- printf("%.2lf\n",buijjhalow(mals,c,n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement