Goodland Electricity

  • + 0 comments

    include

    include

    using namespace std;

    int pylons(int k, const vector& arr) { int need_power = 0; int count = 0;

    while (need_power < arr.size()) {
        bool plant_not_found = true;
    
        for (int i = min(k - 1, int(arr.size()) - need_power - 1); i >= -min(k - 1, need_power); --i) {
            if (arr[need_power + i] == 1) {
                count++;
                need_power += k + i;
                plant_not_found = false;
                break;
            }
        }
    
        if (plant_not_found) return -1;
    }
    
    return count;
    

    }

    int main() { int n, k; cin >> n >> k;

    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    
    int result = pylons(k, arr);
    
    cout << result << "\n";
    
    return 0;
    

    }