Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. //#define FAST_ALLOCATOR_MEMORY 2e8
  6. //#include "optimization.h"
  7.  
  8. using namespace std;
  9.  
  10. #define ALL(x) x.begin(), x.end()
  11.  
  12. typedef long long ll;
  13. typedef unsigned long long ull;
  14. typedef long double ld;
  15. typedef pair<int,int> pii;
  16.  
  17. const int inf = (int)1e9;
  18. const ll md = (ll)1e9 + 7, inf64 = (ll)1e18;
  19.  
  20. int main() {
  21.     iostream::sync_with_stdio(0);
  22.     cin.tie(0), cout.tie(0);
  23.  
  24. #ifdef LOCAL
  25.     freopen("C:\\Users\\aytel\\CLionProjects\\common\\input.txt", "r", stdin);
  26.     freopen("C:\\Users\\aytel\\CLionProjects\\common\\output.txt", "w", stdout);
  27. #endif
  28.  
  29.     int n, m;
  30.     cin >> n >> m;
  31.  
  32.     ll sum = 0;
  33.     vector<ll> diff;
  34.     for (int i = 0; i < n; i++) {
  35.         ll a, b;
  36.         cin >> a >> b;
  37.         sum += a;
  38.         diff.push_back(a - b);
  39.     }
  40.     sort(diff.begin(), diff.end());
  41.     while (diff.size() && sum > m) {
  42.         sum -= diff.back();
  43.         diff.pop_back();
  44.     }
  45.  
  46.     if (sum > m)
  47.         cout << -1;
  48.     else
  49.         cout << n - (diff.size()) << '\n';
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement