[Solution] Final Sum CodeChef Solution | Solution CodeChef
Problem
Chef has an array of length . In one operation, Chef can:
- Choose any subarray ;
- Add to , subtract from , add to , subtract from and so on, till .
Chef performed such operations where the operation was performed on the subarray .
Determine the final sum of the array after these operations.
Note that a subarray is formed by deleting some (possibly zero) elements from the beginning and some (possibly zero) elements from the end of the array.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two integers , number of elements and the number of queries.
- The next line contains space-separated integers - denoting the array .
- The next lines contains two space-separated integers with line containing .
Output Format
For each test case, output the final sum of the array after performing all the operations.
Explanation:
Test case : The queries are as follows:
- Query : The chosen subarray is which changes to . Thus, the array becomes .
- Query : The chosen subarray is which changes to . Thus, the array becomes .
- Query : The chosen subarray is which changes to . Thus, the array becomes .
The sum of final array is .
👇👇👇👇👇
Test case : The queries are as follows:
- Query : The chosen subarray is which changes to . Thus, the array becomes .
- Query : The chosen subarray is which changes to . Thus, the array becomes .
The sum of final array is .
No comments:
Post a Comment