Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <numeric>
- #include <set>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <climits>
- using namespace std;
- const int N = 1e5;
- struct T
- {
- long long c, p;
- bool operator < (const T & other ) const
- {
- return p < other.p;
- }
- };
- T a[N+1];
- long long n, sum = 0, b;
- void read()
- {
- cin >> n >> b;
- for (int i = 1; i <= n; ++ i)
- {
- cin >> a[i].p >> a[i].c;
- }
- sort(a + 1, a + n + 1);
- }
- void solve()
- {
- for (int i = 1; i <= n; ++ i)
- {
- long long tmp = min(a[i].c, b/a[i].p);
- sum += tmp;
- b -= tmp * a[i].p;
- }
- cout << sum;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- read();
- solve();
- }
Add Comment
Please, Sign In to add comment