The Java Program: D_knitting/knitting.java
1 import java.io.*;
2 import java.util.*;
3 import java.awt.*;
4 import java.text.*;
5 import java.math.*;
6
7
8
9
10 class knitting
11 {
12 public Scanner sc;
13 public PrintStream ps;
14
15 public String toString()
16 {
17 return "knitting";
18 }
19
20
21
22
23 public void doit() throws Exception
24 {
25 sc = new Scanner( System.in );
26 ps = System.out;
27
28 for(;;)
29 {
30
31 int n = sc.nextInt();
32 int m = sc.nextInt();
33 int k = sc.nextInt();
34
35
36 if( n==0 && m==0 && k==0 ) break;
37
38
39 int diffs[] = new int[k];
40 for( int i=0; i<k; i++ )
41 {
42 diffs[i] = sc.nextInt();
43 }
44
45
46
47 int total = 0;
48 int row = n;
49 for( int i=0; i<m; i++ )
50 {
51
52 total += row;
53
54
55 row += diffs[i%k];
56 }
57
58
59 ps.println( total );
60 }
61 }
62
63 public static void main(String[] args) throws Exception
64 {
65 long starttime = System.currentTimeMillis();
66 new knitting().doit();
67 System.out.println( System.currentTimeMillis() - starttime );
68 }
69 }