Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Bani
- {
- int ban;
- } b[100], aux;
- int main()
- {
- int n,i,j,S,contor=0,k=0;
- cin >> n >> S;
- for (i=1 ; i<=n; i++)
- cin >> b[i].ban;
- for (i=1 ; i<n ; i++)
- for (j=i+1 ; j<=n ; j++)
- if (b[i].ban < b[j].ban)
- {
- aux = b[i];
- b[i] = b[j];
- b[j] = aux ;
- }
- i=1;
- while (S)
- {
- if(S >= b[i].ban)
- {
- S-=b[i].ban;
- contor++;
- k++;
- }
- else
- {
- cout <<contor << "*" << b[i].ban << endl ;
- contor=0;
- i++;
- }
- }
- cout <<contor << "*" << b[i].ban << endl ;
- cout << k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement