Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

The Universe Loves Minimum Steps!

By Alim14 · Limits 1s, 512 MB

Given an array A of N integers. Your task is to make all the integers 0 by performing the following two operations.

  • Operation 1: You can select K integers arbitrarily from the array where 1 <= K <= N.
  • Operation 2: From the K selected integers, you must have to arbitrarily select A and B integers. You have to arbitrarily select A integers and increase all integers by 1 where 0 <= A <= K and you have to arbitrarily select B integers and decrease all integers by 1 where 0 <= B <= K.

You must perform the above two operations to make all the elements of the array to be 0.

In one step, you can perform the above two operations.

Now your job is to find the minimum number of steps needed to make all the elements of the array to be 0.

Input

Input starts with an integer T (T <= 100), denoting the number of test cases.

Each case contains an integer N(1<=N<=100) and then next line N integers follow. Each integer is between -100 to 100 inclusive.

Output

For each case, print the case number and minimum number of steps needed.

Sample

InputOutput
2
3
7 7 7
4
1 -2 1 2
Case 1: 7
Case 2: 2

This problem was authored for CodeMask Championship 2016 and is being hosted on Toph per organizer’s request.

Discussion

Statistics


92% Solution Ratio

himuhasibEarliest, Oct '17

Nasif_44thFastest, 0.0s

Nasif_44thLightest, 0 B

mdgaziur001Shortest, 105B

Submit

Login to submit

Related Contests

Toph uses cookies. By continuing you agree to our Cookie Policy.