Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cassert>
  4. #include <cctype>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <ctime>
  10. #include <iomanip>
  11. #include <iostream>
  12. #include <map>
  13. #include <queue>
  14. #include <set>
  15. #include <sstream>
  16. #include <string>
  17. #include <vector>
  18.  
  19. using namespace std;
  20.  
  21. const int MAXN = 100;
  22.  
  23. int n, a[MAXN];
  24.  
  25. int main() {
  26.     ios_base::sync_with_stdio(0);
  27.     #ifdef ACMTUYO
  28.         freopen("in.txt","r",stdin);
  29.         freopen("out.txt","w",stdout);
  30.         clock_t start = clock();
  31.     #endif
  32.    
  33.     while (cin >> n) {
  34.         int sum = 0;
  35.         for (int i = 0; i < n; ++i) {
  36.             cin >> a[i];
  37.             sum += a[i];
  38.         }
  39.         int ans = 0;
  40.         while (true) {
  41.             int mag = -1, id = -1;
  42.             for (int i = 1; i < n; ++i) {
  43.                 if (a[i] > mag) {
  44.                     mag = a[i];
  45.                     id = i;
  46.                 }
  47.             }
  48.             if (a[0] > mag)
  49.                 break;
  50.             --a[id];
  51.             ++a[0];
  52.             ++ans;
  53.         }
  54.         cout << ans << '\n';
  55.     }
  56.    
  57.     #ifdef ACMTUYO
  58.         fprintf(stderr, "\ntime=%.3lfsec\n", 1. * (clock() - start) / CLOCKS_PER_SEC);
  59.     #endif
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement