In a vast underground tunnel network spanning N sections, a series of lamps hung from…
- User
In a vast underground tunnel network spanning N sections, a series of lamps hung from the ceiling at regular intervals. Each lamp had a power rating of P, determining the radius of its illumination, effectively lighting up the area from [Pos-P+1, Pos+P-1] when switched on at position Pos. However, the tunnels were not without their challenges. Some of the lamps were malfunctioning, posing a risk to travelers navigating through the darkness. To distinguish between functional and faulty lamps, the tunnel overseer maintained a list, an array A, with N entries corresponding to each lamp's position. A value of 0 signified a faulty lamp, while a value of 1 indicated a functional one. One fateful night, as darkness enveloped the tunnels, the overseer resolved to illuminate the entire underground passage. Yet, mindful of conserving resources, he sought to achieve this feat using the minimum number of lamps necessary. Realizing that failure to fully illuminate the tunnels would jeopardize the safety of travellers, the overseer diligently calculated the precise number of functional lamps required to ensure optimal brightness and safe passage through the depths of the underground network. int power: Power rating of lamp Returns int[n]: minimum number of lamps to be turned 120ON to light the whole tunnel or -1 if the whole tunnel cannot be lighted. Constraints • 1 <= N <= 100000 • 1 <= P <= 10000 nitkkr.ac.in Input Format for Custom Testing ▼Sample Case 0 Sample Input 0 Rank Com A = [0, 0, 1, 1, 1, 0, 0, 1] P = 3 Sample Output 0 2 Explanation Turn on the lamp at 2nd and 7th index. Lamp int arr[n]: Array of size N, The ith index of this
Solve this question in c++ #include <bits/stdc++.h> using namespace std; #define int long long
int rec() {
} signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);
code#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) { }} In this template
- Assistant
- User
so we have constraint n is less than 10^5 and P is 10^4
- Assistant