CF660C.Hard Process
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a with n elements. Each element of a is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).
给你一个包含 $ n $ 个元素的数组 $ a $。数组 $ a $ 的每个元素均为 $ 0 $ 或 $ 1 $。
记 $ f(a) $ 为数组 $ a $ 中由连续的数字 $ 1 $ 构成的最长子段的长度。你可以将至多 $ k $ 个 $ 0 $ 修改为 $ 1 $,以使 $ f(a) $ 尽可能大。
输入格式
The first line contains two integers n and k (1 ≤ n ≤ 3·105, 0 ≤ k ≤ n) — the number of elements in a and the parameter k.
The second line contains n integers a__i (0 ≤ a__i ≤ 1) — the elements of a.
第一行包含两个整数 n 和 k(1≤n≤3⋅105,0≤k≤n)—— 分别表示数组 a 的元素个数和参数 k。
第二行包含 n 个整数 ai(0≤ai≤1)—— 表示数组 a 的元素。
输出格式
On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones.
On the second line print n integers a__j — the elements of the array a after the changes.
If there are multiple answers, you can print any one of them.
第一行输出一个非负整数 z —— 在至多进行 k 次将 0 改为 1 的操作后,f(a) 的最大可能值。
第二行输出 n 个整数 aj —— 经过修改后的数组 a 的各元素。
若存在多个满足条件的答案,输出任意一个即可。
输入输出样例
输入#1
7 1 1 0 0 1 1 0 1
输出#1
4 1 0 0 1 1 1 1
输入#2
10 2 1 0 0 1 0 1 0 1 0 1
输出#2
5 1 0 0 1 1 1 1 1 0 1
输入解题思路,AI测评打分。不知道怎么写?