Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. int n, m, l, b, q;
  8. vector <int> line;
  9. void fill (int x1, int x2) {
  10.     for (int i = x1; i <= x2; ++i) line[i] = 1;
  11. }
  12.  
  13. int count_0 (int x1) {
  14.     int i = x1, count = 0;
  15.     while (line[i] == 0) count++, i++;
  16.     return count;
  17. }
  18.  
  19. void find_the_longest () {
  20.     set <int> longs; //length, coordinate;
  21.     int i = 1, q = -1;
  22.     while (i < m - 1) {
  23.         if (line[i] == 0) {
  24.             q = count_0(i);
  25.             longs.insert(q);
  26.             i += q;
  27.         }
  28.         else i++;
  29.     }
  30.     if (q == -1) {
  31.         cout << 0;
  32.         return;
  33.     }
  34.     auto it = longs.end();
  35.     it--;
  36.     cout << *it;
  37. }
  38.  
  39. int main () {
  40.     cin >> n >> m >> l >> b;
  41.     line.assign(m + 1, 0);
  42.     line[0] = 1;
  43.     line[m] = 1;
  44. //    fill(1, b);
  45. //    fill(m - b, m - 1);
  46.     for (int i = 0; i < n; i++) {
  47.         cin >> q;
  48.         if (q < b) fill(1, q - 1);
  49.         else fill(q - b, q - 1);
  50.         fill(q, q + l - 1);
  51.         if (m - 1 - (q + l - 1) < b) fill(q + l, m - 1);
  52.         else fill(q + l, q + l + b - 1);
  53.     }
  54.     //for (int i = 0; i < m; i++) cout << line[i] << ' ';
  55.     cout << endl;
  56.     find_the_longest();
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement