main.cc 686 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <algorithm>
  2. #include <cstdio>
  3. using namespace std;
  4. const double eps = 1e-6;
  5. struct Candy {
  6. int v;
  7. int w;
  8. bool operator<(const Candy &that) const {
  9. return double(this->v) / this->w - double(that.v) / that.w > eps;
  10. }
  11. };
  12. int main() {
  13. int n, w;
  14. scanf("%d %d", &n, &w);
  15. Candy c[100];
  16. for (int i = 0; i < n; i++) {
  17. scanf("%d %d", &c[i].v, &c[i].w);
  18. }
  19. sort(c, c + n);
  20. int curr_w = 0;
  21. double curr_v = 0.0;
  22. for (int i = 0; i < n; i++) {
  23. if (curr_w + c[i].w <= w) {
  24. curr_w += c[i].w;
  25. curr_v += c[i].v;
  26. } else {
  27. curr_v += double(w - curr_w) / c[i].w * c[i].v;
  28. break;
  29. }
  30. }
  31. printf("%.1f\n", curr_v);
  32. return 0;
  33. }