Advertisement
7oSkaaa

A - Cake

Jul 30th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define cin(vec) for(auto& i : vec) cin >> i
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  7. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  8. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define fixed(n) fixed << setprecision(n)
  11. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  12. #define fill(vec, value) memset(vec, value, sizeof(vec));
  13. #define Num_of_Digits(n) ((int)log10(n)+1)
  14. #define mod_combine(a, b, m) (((a % m) * (b % m)) % m)
  15. #define all(vec) vec.begin(),vec.end()
  16. #define rall(vec) vec.rbegin(),vec.rend()
  17. #define sz(x) int(x.size())
  18. #define TC int t; cin >> t;   while(t--)
  19. #define fi first
  20. #define se second
  21. #define Pair pair < int, int >
  22. #define ll long long
  23. #define ull unsigned long long
  24. #define Mod  1'000'000'007
  25. #define OO 2'000'000'000
  26. #define EPS 1e-9
  27. #define PI acos(-1)
  28.  
  29. void AhMeD_HoSSaM(){
  30.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  31.   #ifndef ONLINE_JUDGE
  32.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  33.   #endif
  34.   freopen("cakes.in", "r", stdin);
  35. }
  36.  
  37. int main(){
  38.   AhMeD_HoSSaM();
  39.   TC {
  40.     ll n, m, curr_cost = 0, Max_Cakes = -OO;
  41.     cin >> n >> m;
  42.     vector < pair < ll, ll > > cakes(n);
  43.     for(auto& [x, t] : cakes) cin >> x;
  44.     for(auto& [x, t] : cakes) cin >> t;
  45.     sort(all(cakes));
  46.     priority_queue < ll > cost;
  47.     for(int i = 0; i < n; i++){
  48.       ll rem = m - cakes[i].fi;
  49.       cost.push(cakes[i].se);
  50.       curr_cost += cakes[i].se;
  51.       while(!cost.empty() && curr_cost > rem){
  52.         curr_cost -= cost.top();
  53.         cost.pop();
  54.       }
  55.       Max_Cakes = max(Max_Cakes, (ll)sz(cost));
  56.     }
  57.     cout << Max_Cakes << "\n";
  58.   }
  59.   Time
  60.   return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement