tuki2501

cbuying.cpp

Sep 20th, 2022
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. int main() {
  7.     int n; ll b;
  8.     cin >> n >> b;
  9.     vector<pair<ll,ll>> a(n);
  10.     for (auto &i : a) {
  11.         cin >> i.first >> i.second;
  12.     }
  13.     sort(a.begin(), a.end());
  14.     ll ans = 0;
  15.     for (auto &i : a) {
  16.         ll t = min(b / i.first, i.second);
  17.         b -= t * i.first;
  18.         ans += t;
  19.     }
  20.     cout << ans << '\n';
  21. }
Advertisement
Add Comment
Please, Sign In to add comment