Advertisement
Josif_tepe

Untitled

Mar 18th, 2022
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(false);
  8. int n;
  9. cin >> n;
  10. int k;
  11. cin >> k;
  12. int a[n];
  13. int sum = 0;
  14. for(int i = 0; i < n; i++) {
  15. cin >> a[i];
  16. if(a[i] == 0) {
  17. a[i] = 1;
  18. }
  19. else {
  20. a[i] = 0;
  21. }
  22. }
  23. int j = 0;
  24. int max_fixed = 0;
  25. for(int i = 0; i < n; i++) {
  26. while(j < n and sum + a[j] <= k) {
  27. sum += a[j];
  28. max_fixed = max(max_fixed, j - i + 1);
  29. j++;
  30. }
  31. sum -= a[i];
  32.  
  33. }
  34. j = 0;
  35. sum = 0;
  36. for(int i = 0; i < n; i++) {
  37. while(j < n and sum + a[j] <= k) {
  38. sum += a[j];
  39. if(max_fixed == j - i + 1) {
  40. cout << max_fixed << endl;
  41. for(int k = i; k <= j; k++) {
  42. if(a[k] == 1) {
  43. cout << k + 1 << " ";
  44. }
  45. }
  46. return 0;
  47. }
  48. j++;
  49. }
  50. sum -= a[i];
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement