# [2016-04-09] [Codeforces] [660] C [Hard Process]

Source: Internet
Author: User

• Time: 2016-04-09-23:59:40 Saturday
• Title Number: [2016-04-09][codeforces][660][c][hard Process]
• Title: Given a sequence of 0 1, the maximum number of K 0 is changed to 1, the longest 1 substring is how long,
• Analysis:
• Check (): Enumerates substrings of mid and determines whether the number of 0 inside is less than or equal to 1,
```

`#include<cstdio>`

`using namespace std;`

`const int maxn = 3*1E5 + 10;`

`int a[maxn],b[maxn],n,k;`

`int check(int x){`

` for(int i = x ; i <= n ; ++i){`

` if(b[i] - b[i - x] + k >= x) return 1;`

` }`

` return 0;`

`}`

`void print(int x){`

` int flg = 0;`

`  for   ( int   i  =   x    I  <=   n     ++  i  ) { `

`  if   ( b  [ i   ]    -  b  [ i  -  x      +   K  >=   x  ) { `

`  for   ( int   J  =   i  -  x  +    1  ;  j  <=   I     ++  j  ) {  `

` a[j] = 1;flg = 1;`

` }`

` }`

` if(flg) break;`

` } `

` for(int i = 1;i <= n ; ++i) printf("%d ",a[i]);`

`}`

`int main(){`

` scanf("%d%d",&n,&k);`

` for(int i = 1 ; i <= n ; ++i){`

` scanf("%d",a+i);`

` b[i] = b[i - 1] + a[i];`

` }`

` int l = 0,r = n + 1,mid,res;`

` while(r >= l){`

` mid = (l + r)>>1;`

` if(check(mid)){`

` l = mid + 1;`

` res = mid;`

` }`

` else r = mid - 1; `

` }`

` printf("%d\n",res);`

` print(res);`

` return 0;`

`}`

```

From for notes (Wiz)

[2016-04-09] [Codeforces] [660] C [Hard Process]

Related Keywords:
Related Article

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.