Advertisement
Guest User

Ferris_wheel_cses

a guest
Nov 7th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define mod 1000000007;
  3. #define ll long long
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n;
  9. ll x;
  10. cin >> n >> x;
  11. ll a[n] = {0};
  12. for (int i = 0; i < n; i++)
  13. {
  14. cin >> a[i];
  15. }
  16. sort(a, a + n);
  17. ll gandola = x;
  18. ll count = 0;
  19. ll ans = 1; // initial gandola count
  20. ll start = 0;
  21. ll end = n - 1;
  22. while (start <= end)
  23. {
  24. if (gandola >= a[start]) // gandola is of sufficient size
  25. {
  26. gandola -= a[start]; // // update gandola weight
  27. }
  28. else
  29. {
  30. ans++; // increase gandola count
  31. gandola = x; // set a new gondola
  32. gandola -= a[start]; // update gandola weight
  33. }
  34. start++;
  35. }
  36. cout << ans;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement