Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // acm
- // uri 1107
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- int h, w, cc, upper_limit, lower_limit, ax, on = 1, floor_;
- vector<int> v;
- while (true) {
- scanf("%d %d", &h, &w);
- if (h == 0)
- return 0;
- v.clear();
- for (int i = 0; i < w; i++) {
- scanf("%d", &ax);
- v.push_back(ax);
- }
- upper_limit = w - 1;
- lower_limit = 0;
- cc = 0;
- floor_ = *min_element(v.begin(), v.end());
- for (int i = h; i > floor_; i--) {
- on = 1;
- while (v[lower_limit] >= i)
- lower_limit++;
- while (v[upper_limit] >= i)
- upper_limit--;
- for (int j = lower_limit; j <= upper_limit; j++) {
- if (v[j] >= i) {
- if (on == 1) {
- on = 0;
- }
- } else if(on == 0) {
- on = 1;
- cc++;
- }
- }
- cc++;
- }
- printf("%d\n", cc);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement