CF #edu C. Hard Process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.