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 pref_sum[n];
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- if(a[i] == 0) {
- sum += 1;
- }
- pref_sum[i] = sum;
- }
- int max_fixed = 0;
- for(int i = 0; i < n; i++) {
- int L = i + 1;
- int R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- int zeros = pref_sum[middle];
- if(i - 1 >= 0) {
- zeros -= pref_sum[i - 1];
- }
- if(zeros <= k) {
- max_fixed = max(max_fixed, middle - i + 1);
- L = middle + 1;
- }
- else {
- R = middle - 1;
- }
- }
- }
- for(int i = 0; i < n; i++) {
- int L = i + 1;
- int R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- int zeros = pref_sum[middle];
- if(i - 1 >= 0) {
- zeros -= pref_sum[i - 1];
- }
- if(zeros <= k) {
- if(max_fixed == middle - i + 1) {
- cout << max_fixed << endl;
- for(int j = i; j <= middle; j++) {
- if(a[j] == 0) {
- cout << j + 1 << " ";
- }
- }
- return 0;
- }
- L = middle + 1;
- }
- else {
- R = middle - 1;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement