Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <fstream>
- using namespace std;
- int n, m, l, b, q;
- vector <int> line;
- void fill (int x1, int x2) {
- for (int i = x1; i <= x2; ++i) line[i] = 1;
- }
- int count_0 (int x1) {
- int i = x1, count = 0;
- while (line[i] == 0) count++, i++;
- return count;
- }
- void find_the_longest () {
- set <int> longs; //length, coordinate;
- int i = 1, q = -1;
- while (i < m - 1) {
- if (line[i] == 0) {
- q = count_0(i);
- longs.insert(q);
- i += q;
- }
- else i++;
- }
- if (q == -1) {
- cout << 0;
- return;
- }
- auto it = longs.end();
- it--;
- cout << *it;
- }
- int main () {
- cin >> n >> m >> l >> b;
- line.assign(m + 1, 0);
- line[0] = 1;
- line[m] = 1;
- // fill(1, b);
- // fill(m - b, m - 1);
- for (int i = 0; i < n; i++) {
- cin >> q;
- if (q < b) fill(1, q - 1);
- else fill(q - b, q - 1);
- fill(q, q + l - 1);
- if (m - 1 - (q + l - 1) < b) fill(q + l, m - 1);
- else fill(q + l, q + l + b - 1);
- }
- //for (int i = 0; i < m; i++) cout << line[i] << ' ';
- cout << endl;
- find_the_longest();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement