SHOW:
|
|
- or go back to the newest paste.
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 | - | cout << gandola << " " << a[start] << endl; |
26 | + | |
27 | } | |
28 | else | |
29 | { | |
30 | ans++; // increase gandola count | |
31 | - | cout << gandola << " " << a[start] << "icre" << endl; |
31 | + | |
32 | gandola -= a[start]; // update gandola weight | |
33 | } | |
34 | start++; | |
35 | } | |
36 | cout << ans; | |
37 | } | |
38 |