Advertisement
Saleh127

Untitled

Apr 17th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int a[100],b,c=0,d=0,e=0,f,i,j,k,l;
  6. cin>>b;
  7. for(i=0;i<12;i++)
  8. {
  9. cin>>a[i];
  10. e+=a[i];
  11. }
  12. if(e<b) cout<<-1<<endl;
  13. else if(b==0) cout<<0<<endl;
  14. else
  15. {
  16. sort(a,a+12,greater<int>());
  17. for(i=0;i<12;i++)
  18. {
  19. c+=a[i];
  20. if(c<b)
  21. {
  22. d++;
  23. }
  24. else
  25. {
  26. d+=1;
  27. break;
  28. }
  29. }
  30. cout<<d<<endl;
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement