Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("date.in");
- int n,GMax;
- struct elem
- {
- float R,G,V;
- };
- elem a[100],auxiliar;
- void citire()
- {
- f >> n >> GMax;
- for(int i=1;i<=n;i++)
- {f >> a[i].G >> a[i].V;
- a[i].R = a[i].V/a[i].G;
- }
- }
- int sortare(int st,int dr)
- {int aux,di,dj,i,j;
- i=st;
- j=dr;
- di=0;
- dj=1;
- while(i<j)
- {
- if(a[i].R<a[j].R)
- {
- auxiliar=a[i];
- a[i]=a[j];
- a[j]=auxiliar;
- aux=di;
- di=dj;
- dj=aux;
- }
- i=i+di;
- j=j-dj;
- }
- return i;
- }
- void quick(int st, int dr)
- {int x;
- if(st<dr)
- {
- x=sortare(st,dr);
- quick(st,x-1);
- quick(x+1,dr);
- }
- }
- void rezolva(int GMax)
- {int k=1;
- int Gcur=0;
- int Vmax=0;
- float Frc;
- while(Gcur<GMax)
- {
- if(Gcur+a[k].G>GMax)
- {
- Frc=((a[k].G-(GMax-Gcur))/(a[k].G*1.0))*a[k].V;
- Vmax = Vmax + Frc;
- Gcur = Gcur + (GMax-a[k].G);
- }
- else
- {
- Gcur=Gcur+a[k].G;
- Vmax=Vmax+a[k].V;
- }
- k++;
- }
- cout << Vmax;
- }
- int main()
- {
- citire();
- quick(1,n);
- rezolva(GMax);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement