Question: Better Together Twice Problem Statement In an array A containing N elements, each element is initially assigned its own value. Over time, the values evolve

Better Together Twice
Problem Statement
In an array A containing N elements, each element is initially assigned its own value. Over time, the values evolve such that non-zero elements increase the value of their adjacent elements by 2 each day. Specifically, if the \( i \)-th element holds a non-zero value, both the (\( i-1\))-th and (\( i+1\))-th elements (if they exist) increase by 2.
The initial day is designated as day 0, with subsequent days denoted as day 1, day 2, and so forth. The task is to compute the difference between the additon of values of all elements on day \( P \) and additon of values of all elements on day 0.
Input Format
First line contains two integers N and P representing size of array and the Pth day.
Second line contains N integers value of each element on day 0.
Output Format
A single integer representing the difference in the total sum of all elements between day \( P \) and day 0.
Constraints
\[
\begin{array}{l}
1=N, F=10^{8}\\
0=A[i]=10^{8}
\end{array}
\]
Sample Testcase 1
Testcase Input
17
10
Testcase Output
Better Together Twice Problem Statement In an

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!