fork download
  1. #include<bits/stdc++.h>
  2. #define f1(i, n) for(ll i=1;i<=n;++i)
  3. #define f0(i, n) for(ll i=0;i<n;++i)
  4. #define ull unsigned long long
  5. #define ll long long
  6. #define rev(a) reverse(a.begin(),a.end())
  7. #define all(x) x.begin(),x.end()
  8. #define so(A, n) sort(A+1, A+n+1)
  9. using namespace std;
  10. const int maxn = 200010;
  11. const int N = 2e5 + 5;
  12. int A[N], T[N];
  13. void solve() {
  14. int n, k;
  15. cin >> n >> k;
  16. f1(i, n) {
  17. cin >> A[i];
  18. T[i] = T[i - 1] + A[i];
  19. }
  20. int cnt = 0, res = 0;
  21. int i = 1, j = 1;
  22. while (j <= n) {
  23. if (cnt > k) {
  24. while (cnt > k) {
  25. if (A[i] == 0) {
  26. --cnt;
  27. }
  28. ++i;
  29. }
  30. }
  31. else {
  32. res = max(res, j - i + 1);
  33. }
  34. if (A[j] == 0) {
  35. cnt++;
  36. }
  37. ++j;
  38. }
  39. cout << res << endl;
  40. for (int i = res; i <= n; ++i) {
  41. if (res - T[i] + T[i - res] <= k) {
  42. for (int j = 1; j <= i - res; j++) {
  43. cout << A[j] << " ";
  44. }
  45. for (int j = i - res + 1; j <= i; ++j) {
  46. cout << 1 << " ";
  47. }
  48. for (int j = i + 1; j <= n; ++j) {
  49. cout << A[j] << " ";
  50. }
  51. return;
  52. }
  53. }
  54. }
  55. int main()
  56. {
  57. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  58. solve();
  59.  
  60. return 0;
  61. }
  62.  
  63.  
  64.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
0