Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int n, G, v[1001], cas, i;
- int main()
- {
- cin >> n >> G;
- for( int i = 1; i <= n; i++ )
- {
- cin >> v[i];
- }
- sort(v+1,v+1+n);
- for( int i = n; i >= 1; i-- )
- {
- if( G - v[i] >= 0 )
- {
- G -= v[i];
- cas++;
- }
- }
- if( G != 0 ) cout << "NU";
- else cout << cas;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement