Advertisement
a53

centre

a53
Oct 17th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. # include <fstream>
  2. # include <algorithm>
  3. # define NR 5005
  4. using namespace std;
  5. ifstream f("centre.in");
  6. ofstream g("centre.out");
  7. int i,j,n,m,cx,cy,S;
  8. struct elem
  9. {
  10. int x, y, dif, cere;
  11. }a[NR];
  12. bool cmp (elem x, elem y)
  13. {
  14. if (x.dif>=y.dif) return 0;
  15. else return 1;
  16. }
  17. int main ()
  18. {
  19. f>>n>>cx>>cy;
  20.  
  21. for (i=1; i<=n; ++i) f>>a[i].cere;
  22. for (i=1; i<=n; ++i) f>>a[i].x;
  23. for (i=1; i<=n; ++i) f>>a[i].y;
  24.  
  25. for (i=1; i<=n; ++i)
  26. a[i].dif=a[i].x-a[i].y;
  27.  
  28. sort (a+1, a+n+1, cmp);
  29.  
  30. for (i=1; i<=n; ++i)
  31. {
  32. if (cx)
  33. {
  34. if (cx>=a[i].cere) S+=a[i].cere * a[i].x, cx-=a[i].cere;
  35. else {
  36. S+=cx * a[i].x;
  37. S+=(a[i].cere - cx) * a[i].y;
  38.  
  39. cy-=(a[i].cere - cx); cx=0;
  40. }
  41. }
  42. else S+=a[i].cere * a[i].y, cy-=a[i].cere;
  43. }
  44. g<<S<<"\n";
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement