Title Link: Http://codeforces.com/problemset/problem/660/C
Ruler, each time you encounter 0 of the time to fill a 1, until the completion or out of bounds. Each time a 0 point is recycled from left to right. The recording path is jammed with two pointers, each updated.
1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstring>5#include <climits>6#include <complex>7#include <fstream>8#include <cassert>9#include <cstdio>Ten#include <bitset> One#include <vector> A#include <deque> -#include <queue> -#include <stack> the#include <ctime> -#include <Set> -#include <map> -#include <cmath> + - using namespacestd; + A Const intMAXN =666666; at intN, K; - intA[MAXN]; - - intMain () { - //freopen ("in", "R", stdin); - while(~SCANF ("%d%d", &n, &k)) { in for(inti =1; I <= N; i++) { -scanf"%d", &a[i]); to } + intLL =1; - intRR =1; the intAl =0; * intAR =0; $ intCur =0;Panax Notoginseng intAns =0; - while(1) { the if(RR > N) Break; + while(RR <= n && cur <=k) { A if(A[RR] = =0) { the if(cur = = k) Break; +cur++; - } $rr++; $ } - if(Rr-ll >ans) { -Ans = rr-ll; theAl =ll; -AR = RR-1;Wuyi } the while(ll <= rr && a[ll] = =1) ll++; -cur--; Wull++; - } Aboutprintf"%d\n", ans); $ for(inti =1; I <= N; i++) { - if(I >= al && i <= ar) printf ("1"); - Elseprintf"%d", A[i]); - } Aprintf"\ n"); + } the return 0; -}
[cf660c] Hard Process (ruler)