Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ifstream f("date.in");
  5. int n,GMax;
  6. struct elem
  7. {
  8. float R,G,V;
  9. };
  10. elem a[100],auxiliar;
  11. void citire()
  12. {
  13. f >> n >> GMax;
  14. for(int i=1;i<=n;i++)
  15. {f >> a[i].G >> a[i].V;
  16. a[i].R = a[i].V/a[i].G;
  17. }
  18. }
  19. int sortare(int st,int dr)
  20. {int aux,di,dj,i,j;
  21. i=st;
  22. j=dr;
  23. di=0;
  24. dj=1;
  25. while(i<j)
  26. {
  27. if(a[i].R<a[j].R)
  28. {
  29. auxiliar=a[i];
  30. a[i]=a[j];
  31. a[j]=auxiliar;
  32. aux=di;
  33. di=dj;
  34. dj=aux;
  35. }
  36. i=i+di;
  37. j=j-dj;
  38. }
  39. return i;
  40. }
  41. void quick(int st, int dr)
  42. {int x;
  43. if(st<dr)
  44. {
  45. x=sortare(st,dr);
  46. quick(st,x-1);
  47. quick(x+1,dr);
  48. }
  49. }
  50. void rezolva(int GMax)
  51. {int k=1;
  52. int Gcur=0;
  53. int Vmax=0;
  54. float Frc;
  55. while(Gcur<GMax)
  56. {
  57. if(Gcur+a[k].G>GMax)
  58. {
  59. Frc=((a[k].G-(GMax-Gcur))/(a[k].G*1.0))*a[k].V;
  60. Vmax = Vmax + Frc;
  61. Gcur = Gcur + (GMax-a[k].G);
  62. }
  63. else
  64. {
  65. Gcur=Gcur+a[k].G;
  66. Vmax=Vmax+a[k].V;
  67. }
  68. k++;
  69. }
  70. cout << Vmax;
  71. }
  72. int main()
  73. {
  74. citire();
  75. quick(1,n);
  76. rezolva(GMax);
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement