fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. #define ll long long
  5. #define N 1e6
  6. ll A[1000001], n, i, a, c, j, ma = 0, t = 0, mi, k, d = 0, res = 0, MOT[100000], KO[100000], te = 0, x;
  7. pair<ll, ll> v[1000001];
  8. int main()
  9. {
  10. faster
  11. cin >> n >> k;
  12. for (i = 1; i <= n; i++)
  13. {
  14. cin >> A[i];
  15. if (A[i] == 1) d++;
  16. else
  17. {
  18. if (d != 0)
  19. {
  20. t++;
  21. MOT[t] = d;
  22. cout << MOT[t] << "_";
  23. d = 0;
  24. }
  25.  
  26. }
  27. }
  28. t++;
  29. MOT[t] = d;
  30. cout << MOT[t] << endl;
  31. d = 0;
  32. for (i = 1; i <= n; i++)
  33. {
  34. if (A[i] == 0) d++;
  35. else
  36. {
  37. if (d != 0)
  38. {
  39. te++;
  40. KO[te] = d;
  41. cout << KO[te] << " ";
  42. d = 0;
  43. }
  44.  
  45. }
  46. }
  47. if (d != 0)
  48. {
  49. te++;
  50. KO[te] = d;
  51. cout << KO[te] << " ";
  52. }
  53. ll left = 1, cnt0 = 0, maxlen = 0;
  54. for (ll right = 1; right <= n; right++) {
  55. if (A[right] == 0) cnt0++;
  56. while (cnt0 > k) {
  57. if (A[left] == 0) cnt0--;
  58. left++;
  59. }
  60. maxlen = max(maxlen, right - left + 1);
  61. }
  62. cout << endl << maxlen;
  63. }
Success #stdin #stdout 0s 5636KB
stdin
Standard input is empty
stdout
0

0