// No.156 キャンディー・ボックス // https://yukicoder.me/problems/no/156 // #include #include using namespace std; int main() { int N, M; cin >> N >> M; priority_queue pq; for (auto i = 0; i < N; ++i) { int tmp; cin >> tmp; pq.push(-tmp); } int ans = 0; while (M > 0) { if (pq.empty()) break; int candy = pq.top(); pq.pop(); M += candy; if (M >= 0) ++ans; } cout << ans << endl; }