Weightlifting solution codejam
Problem
You are following a prescribed training for weightlifting. The training consists of a series of exercises that you must do in order. Each exercise requires a specific set of weights to be placed on a machine. There are WW types of different weights. For example, an exercise may require 33 weights of type A and 11 weight of type B, while the next requires 22 weights each of types A, C, and D.Weightlifting solution codejam
The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with a line containing 22 integers EE and WW: the number of exercises and the number of types of weights. Weight types are numbered between 11 and WW. Then, EE lines follow. The iith of these lines contains WW integers Xi,1,Xi,2,…,Xi,WXi,1,Xi,2,…,Xi,W representing that the iith exercise requires exactly Xi,jXi,j weights of type jj.Output
For each test case, output one line containingCase #xx: yy
, where xx is the test case number (starting from 1) and yy is the minimum number of machine stack operations needed to run through all your exercises.
Weightlifting solution codejam
Time limit: 20 seconds. Memory limit: 1 GB. 1≤T≤1001≤T≤100. 1≤Xi,1+Xi,2+⋯+Xi,W1≤Xi,1+Xi,2+⋯+Xi,W, for all ii. (Each exercise requires at least one weight.)Test Set 1 (Visible Verdict)
1≤E≤101≤E≤10. 1≤W≤31≤W≤3. 0≤Xi,j≤30≤Xi,j≤3, for all i,ji,j.Test Set 2 (Hidden Verdict)
1≤E≤1001≤E≤100. 1≤W≤1001≤W≤100. 0≤Xi,j≤1000≤Xi,j≤100, for all i,ji,j.Weightlifting solution codejam
Sample Input
3 3 1 1 2 1 2 3 1 2 1 2 1 2 3 3 3 1 1 3 3 3 2 3 3
Sample Output
Case #1: 4 Case #2: 12 Case #3: 20
 Add a weight onto the stack. You do the first exercise.
 Add a weight onto the stack. You do the second exercise.
 Remove a weight from the top of the stack. You do the third exercise.
 Remove a weight from the top of the stack. Now the stack becomes empty.
 Add a weight of type 22.
 Add a weight of type 33.
 Add a weight of type 11.
 Add a weight of type 22. Now the stack contains weights of types 2,3,1,22,3,1,2 from bottom to top. You do the first exercise.
 Remove a weight of type 22 from the top of the stack.
 Add a weight of type 33.
 Add a weight of type 11. Now the stack contains weights of types 2,3,1,3,12,3,1,3,1 from bottom to top. You do the second exercise.
 Remove a weight of type 11 from the top of the stack.
 Remove a weight of type 33 from the top of the stack.
 Remove a weight of type 11 from the top of the stack.
 Remove a weight of type 33 from the top of the stack.
 Remove a weight of type 22 from the top of the stack. Now the stack becomes empty.

ANSWER
“Click Here“