Anik_Akash

D - Strange Lunchbox

Sep 18th, 2021 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace    std;
  3.  
  4. #define flush                    cin.ignore(numeric_limits<streamsize>::max(),'\n')
  5. #define FASTERIO                 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6. #define NL                       cout<<'\n';
  7. #define pi                       acos(-1.0) //3.1415926535897932384626
  8. #define pb                       push_back
  9. #define mk                       make_pair
  10. #define mx                       100005
  11. #define EPS                      1e-10
  12. #define dpoint(x)                fixed<<setprecision(x)
  13. typedef long long int            ll;
  14. typedef double                   dl;
  15. typedef unsigned long long int   ull;
  16.  
  17. //Funtions
  18. template <class T> T digitsum(T n) {T sum = 0; while (n != 0) {sum += n % 10; n /= 10;} return sum;}
  19. int gcd(int a, int b) { int x ; return x = __gcd(a, b);}
  20. int lcm(int a, int b) {int y; return y = ((a) * ((b) / gcd(a, b)));}
  21.  
  22. // Debugger
  23. #define gobug                   0
  24. #define debugNS(a,b,c)          cout<<a<<b<<c<<endl;
  25. #define debugN(b)               cout<<b<<endl;
  26.  
  27. bool cmp(pair<int, int>a, pair<int, int>b) {
  28.     if(a<b)return true;
  29.     return false;
  30. }
  31.  
  32.  
  33. int main() {
  34.  
  35.  
  36.     FASTERIO; //cmt when use scanf & printf ;
  37.  
  38.  
  39.    int tt, n; cin>>tt;
  40.    int x,y; cin>>x>>y;
  41.    n = tt;
  42.    vector<pair<int,int>>mp;
  43.    while(tt--){
  44.         int a,b; cin>>a>>b;
  45.         mp.pb({a,b});
  46.    }
  47.    
  48.  
  49.    for(int i=0; i<n; i++){
  50.     for(int j=i+1; j<n; j++){
  51.         if(cmp(mp[i],mp[j]))swap(mp[i],mp[j]);
  52.     }
  53.    }
  54.  
  55.    
  56.     bool flg = false;
  57.     int boll=0, ric=0, cnt=0;
  58.     for(auto it:mp){
  59.         boll+=it.first;
  60.         ric+=it.second;
  61.         cnt++;
  62.         if(boll >= x && ric>=y){
  63.             flg = true; break;
  64.         }
  65.     }
  66.     if(flg)cout<<cnt<<endl;
  67.     else cout<<-1<<endl;
  68.  
  69.  
  70.  
  71.     return 0;
  72. }
Add Comment
Please, Sign In to add comment