irapilguy

Светлячки2

Nov 13th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define N 200000
  4. #define H 500000
  5. int hight[N] = { 0 };
  6. int res[H] = { 0 };
  7. void way( int h) {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(NULL);
  10.     int min = res[1];
  11.     int  count = 0;
  12.     for (int i = 1; i <= h; i++) {
  13.         if (res[i] == min) count++;
  14.         if (min > res[i]) {
  15.             count = 1;
  16.             min = res[i];
  17.         }
  18.     }
  19.     cout << min << " " << count;
  20. }
  21. int main() {
  22.     ios_base::sync_with_stdio(false);
  23.     cin.tie(NULL);
  24.     int n, h;
  25.     cin >> n >> h;
  26.     for (int i = 1; i <= n; i++) {
  27.         int x;
  28.         cin >> x;
  29.         if (i % 2 == 0) {
  30.             hight[h - x + 1]++;
  31.         }
  32.         else {
  33.             hight[1]++;
  34.             hight[x + 1]--;
  35.         }
  36.     }
  37.     res[1] = hight[1];
  38.     for (int i = 2; i <= h; i++) res[i] = res[i - 1] + hight[i];
  39.     way(h);
  40.     return 0;
  41. }
Add Comment
Please, Sign In to add comment