Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. // acm
  2. // uri 1107
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.  
  12.   int h, w, cc, upper_limit, lower_limit, ax, on = 1, floor_;
  13.   vector<int> v;
  14.  
  15.   while (true) {
  16.     scanf("%d %d", &h, &w);
  17.     if (h == 0)
  18.       return 0;
  19.  
  20.     v.clear();
  21.     for (int i = 0; i < w; i++) {
  22.       scanf("%d", &ax);
  23.       v.push_back(ax);
  24.     }
  25.  
  26.     upper_limit = w - 1;
  27.     lower_limit = 0;
  28.     cc = 0;
  29.     floor_ = *min_element(v.begin(), v.end());
  30.  
  31.     for (int i = h; i > floor_; i--) {
  32.       on = 1;
  33.  
  34.       while (v[lower_limit] >= i)
  35.         lower_limit++;
  36.       while (v[upper_limit] >= i)
  37.         upper_limit--;
  38.  
  39.       for (int j = lower_limit; j <= upper_limit; j++) {
  40.         if (v[j] >= i) {
  41.           if (on == 1) {
  42.             on = 0;
  43.           }
  44.         } else if(on == 0) {
  45.           on = 1;
  46.           cc++;
  47.         }
  48.       }
  49.       cc++;
  50.     }
  51.  
  52.     printf("%d\n", cc);
  53.   }
  54.  
  55.   return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement