Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define mod 1000000007;
- #define ll long long
- using namespace std;
- int main()
- {
- int n;
- ll x;
- cin >> n >> x;
- ll a[n] = {0};
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- }
- sort(a, a + n);
- ll gandola = x;
- ll count = 0;
- ll ans = 1; // initial gandola count
- ll start = 0;
- ll end = n - 1;
- while (start <= end)
- {
- if (gandola >= a[start]) // gandola is of sufficient size
- {
- gandola -= a[start]; // // update gandola weight
- }
- else
- {
- ans++; // increase gandola count
- gandola = x; // set a new gondola
- gandola -= a[start]; // update gandola weight
- }
- start++;
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement