Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, max, w, i, p=1, o=0;
- cin >> n;
- int niza[50];
- for(i=0; i<n; i++) cin >> niza[i];
- while(p!=0){
- max=0;
- for(w=0; w<n; w++){
- {
- if(max<=niza[w]){
- max = niza[w];
- p = w;
- }
- }
- }
- if(p==0) break;
- if(niza[0]<=niza[p]){
- niza[0]++;
- niza[p]--;
- o++;
- }
- }
- cout << o;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment