Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <iomanip>
- #include <random>
- #include <ctime>
- #include <bitset>
- #include <map>
- #include <set>
- #include <unordered_map>
- #include <unordered_set>
- #include <cmath>
- #include <climits>
- #include <cstring>
- #include <queue>
- #include <deque>
- #include <list>
- #include <stack>
- #define pb push_back
- #define ff first
- #define ss second
- #define sqr(x) (x) * (x)
- #define cb(x) (x) * (x) * (x)
- #define SIZE 101
- #define INF 1e18 + 9
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pii;
- typedef pair<ll, ll> pll;
- const int inf = 2e9;
- const ll linf = 2e18;
- const ll mod = 1e9 + 7;
- template <typename T>
- ostream& operator << (ostream& s, vector<T>& v) {
- for (auto el : v) {
- s << el << " ";
- }
- return s;
- }
- bool cmp(pii a, pii b) {
- ld xa = a.ff * 1.0 / a.ss;
- ld xb = b.ff * 1.0 / b.ss;
- return xa > xb;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0), cout.tie(0);
- int n, w; cin >> n >> w;
- vector<pii> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i].ff >> a[i].ss;
- }
- sort(a.begin(), a.end(), cmp);
- ld res = 0;
- for (int i = 0; i < n; i++) {
- if (w >= a[i].ss) {
- res += a[i].ff;
- w -= a[i].ss;
- }
- else {
- res += (a[i].ff * 1.0 / a[i].ss) * w;
- w = 0;
- }
- }
- cout << setprecision(10) << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement