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