velimir

izbori2

Apr 5th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, max, w, i,  p=1, o=0;
  8.     cin >> n;
  9.     int niza[50];
  10.     for(i=0; i<n; i++) cin >> niza[i];
  11.     while(p!=0){
  12.         max=0;
  13.         for(w=0; w<n; w++){
  14.             {
  15.                 if(max<=niza[w]){
  16.                     max = niza[w];
  17.                     p = w;
  18.                 }
  19.             }
  20.         }
  21.             if(p==0) break;
  22.             if(niza[0]<=niza[p]){
  23.                 niza[0]++;
  24.                 niza[p]--;
  25.                 o++;
  26.             }
  27.     }
  28.     cout << o;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment