SHARE
TWEET

Untitled

Khody Feb 27th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <iomanip>
  5. #include <random>
  6. #include <ctime>
  7. #include <bitset>
  8. #include <map>
  9. #include <set>
  10. #include <unordered_map>
  11. #include <unordered_set>
  12. #include <cmath>
  13. #include <climits>
  14. #include <cstring>
  15. #include <queue>
  16. #include <deque>
  17. #include <list>
  18. #include <stack>
  19.  
  20. #define pb push_back
  21. #define ff first
  22. #define ss second
  23. #define sqr(x) (x) * (x)
  24. #define cb(x) (x) * (x) * (x)
  25. #define SIZE 101
  26. #define INF 1e18 + 9
  27.  
  28.  
  29. using namespace std;
  30.  
  31. typedef long long ll;
  32. typedef long double ld;
  33. typedef pair<int, int> pii;
  34. typedef pair<ll, ll> pll;
  35.  
  36. const int inf = 2e9;
  37. const ll linf = 2e18;
  38. const ll mod = 1e9 + 7;
  39.  
  40. template <typename T>
  41. ostream& operator << (ostream& s, vector<T>& v) {
  42.     for (auto el : v) {
  43.         s << el << " ";
  44.     }
  45.     return s;
  46. }
  47.  
  48. bool cmp(pii a, pii b) {
  49.     ld xa = a.ff * 1.0 / a.ss;
  50.     ld xb = b.ff * 1.0 / b.ss;
  51.     return xa > xb;
  52. }
  53.  
  54.  
  55. int main() {
  56.     ios_base::sync_with_stdio(0);
  57.     cin.tie(0), cout.tie(0);
  58.     int n, w; cin >> n >> w;
  59.     vector<pii> a(n);
  60.     for (int i = 0; i < n; i++) {
  61.         cin >> a[i].ff >> a[i].ss;
  62.     }
  63.     sort(a.begin(), a.end(), cmp);
  64.     ld res = 0;
  65.     for (int i = 0; i < n; i++) {
  66.         if (w >= a[i].ss) {
  67.             res += a[i].ff;
  68.             w -= a[i].ss;
  69.         }
  70.         else {
  71.             res += (a[i].ff * 1.0 / a[i].ss) * w;
  72.             w = 0;
  73.         }
  74.     }
  75.     cout << setprecision(10) << res << endl;
  76.     return 0;
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top