Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct obiect
- {
- int nr,gr,c;
- float ef;
- }v[2000];
- int G,n;
- int main()
- {
- cin>>n>>G;
- for(int i=1;i<=n;i++)
- {
- v[i].nr=i;
- cin>>v[i].gr>>v[i].c;
- v[i].ef=(v[i].c*1.0)/v[i].gr;
- }
- for(int i=1;i<n;i++)
- for(int j=i+1;j<=n;j++)
- if(v[i].ef<v[j].ef)
- swap(v[i],v[j]);
- float C=0;
- int i=1;
- while(i<=n && G>0)
- {
- if(v[i].gr<=G)
- {
- C=C+v[i].c;
- G=G-v[i].gr;
- }
- else
- {
- C=C+v[i].c*((G*1.0)/v[i].gr);
- G=G-v[i].gr*((G*1.0)/v[i].gr);
- }
- i++;
- }
- cout<<C;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement