Title Link: Http://codeforces.com/problemset/problem/660/C
The effect is to give a 01 array, at most can be K 0 to 1, ask the last array of the longest can have how many consecutive 1, and output.
Problem transformation is to find an interval, so that the number of 0 in the interval is not more than k, and the interval length as long as possible. You can do it with a ruler.
ImportJava.io.OutputStream;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.PrintWriter;ImportJava.util.StringTokenizer;Importjava.io.IOException;ImportJava.io.BufferedReader;ImportJava.io.InputStreamReader;ImportJava.io.InputStream; Public classMain { Public Static voidMain (string[] args) {InputStream InputStream=system.in; OutputStream OutputStream=System.out; Inputreader in=NewInputreader (InputStream); PrintWriter out=NewPrintWriter (OutputStream); Task Solver=NewTask (); Solver.solve (1, in, out); Out.close (); } Static classTask { Public voidSolveintTestnumber, Inputreader in, printwriter out) { intn = In.nextint (), k =In.nextint (); int[] A =New int[n]; intL = 0; intCNT = 0; intRET = 0; intL =-1, R = 1; for(intR = 0; R < N; r++) {A[r]=In.nextint (); CNT+ = 1-A[r]; while(CNT >k) {CNT-= 1-a[l++]; } if(R-l + 1 >=ret) {ret= r-l + 1; L=l; R=R; }} out.println (ret); for(inti = 0; I < n; i++) { if(L <= i && i <=R) {out.print (1); } Else{out.print (a[i]); } out.print (" "); } } } Static classInputreader {PrivateBufferedReader Reader; PrivateStringTokenizer Tokenizer; PublicInputreader (InputStream stream) {Reader=NewBufferedReader (NewInputStreamReader (stream)); Tokenizer=NULL; } PublicString Next () { while(Tokenizer = =NULL|| !Tokenizer.hasmoretokens ()) { Try{Tokenizer=NewStringTokenizer (Reader.readline ()); } Catch(IOException e) {Throw NewRuntimeException (e); } } returnTokenizer.nexttoken (); } Public intNextint () {returnInteger.parseint (Next ()); } }}
CF #edu One-to-one C. Hard Process