12345678910111213141516171819202122232425262728293031323334353637 |
- #include <algorithm>
- #include <cstdio>
- using namespace std;
- const double eps = 1e-6;
- struct Candy {
- int v;
- int w;
- bool operator<(const Candy &that) const {
- return double(this->v) / this->w - double(that.v) / that.w > eps;
- }
- };
- int main() {
- int n, w;
- scanf("%d %d", &n, &w);
- Candy c[100];
- for (int i = 0; i < n; i++) {
- scanf("%d %d", &c[i].v, &c[i].w);
- }
- sort(c, c + n);
- int curr_w = 0;
- double curr_v = 0.0;
- for (int i = 0; i < n; i++) {
- if (curr_w + c[i].w <= w) {
- curr_w += c[i].w;
- curr_v += c[i].v;
- } else {
- curr_v += double(w - curr_w) / c[i].w * c[i].v;
- break;
- }
- }
- printf("%.1f\n", curr_v);
- return 0;
- }
|