Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- int k;
- cin >> k;
- int a[n];
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- if(a[i] == 0) {
- a[i] = 1;
- }
- else {
- a[i] = 0;
- }
- }
- int j = 0;
- int max_fixed = 0;
- for(int i = 0; i < n; i++) {
- while(j < n and sum + a[j] <= k) {
- sum += a[j];
- max_fixed = max(max_fixed, j - i + 1);
- j++;
- }
- sum -= a[i];
- }
- j = 0;
- sum = 0;
- for(int i = 0; i < n; i++) {
- while(j < n and sum + a[j] <= k) {
- sum += a[j];
- if(max_fixed == j - i + 1) {
- cout << max_fixed << endl;
- for(int k = i; k <= j; k++) {
- if(a[k] == 1) {
- cout << k + 1 << " ";
- }
- }
- return 0;
- }
- j++;
- }
- sum -= a[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement