23dfcca431 2011-02-23 kinaba: using System; 23dfcca431 2011-02-23 kinaba: using System.Linq; 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: class C 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: static void Main() 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: long[] Ts = readLongArray(); 23dfcca431 2011-02-23 kinaba: long T = Ts[0]; 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: for(long C=1; C<=T; ++C) 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: long[] RkN = readLongArray(); 23dfcca431 2011-02-23 kinaba: long R = RkN[0]; 23dfcca431 2011-02-23 kinaba: long k = RkN[1]; 23dfcca431 2011-02-23 kinaba: long N = RkN[2]; 23dfcca431 2011-02-23 kinaba: long[] g = readLongArray(); 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: Console.WriteLine("Case #{0}: {1}", C, solveSmall(R,k,N,g)); 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: static long[] readLongArray() 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: return (from s in Console.ReadLine().Split(' ') select long.Parse(s)).ToArray(); 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: static long solveSmall(long R, long k, long N, long[] g) 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: long totalEarn = 0; 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: for(int i=0; i<R; ++i) 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: long ride = 0; 23dfcca431 2011-02-23 kinaba: for(int q=0; q<g.Length; ++q) 23dfcca431 2011-02-23 kinaba: if( ride + g[q] > k ) 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: g = rotate(g, q); 23dfcca431 2011-02-23 kinaba: break; 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: else 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: ride += g[q]; 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: totalEarn += ride; 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: return totalEarn; 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: static long[] rotate(long[] g, int s) 23dfcca431 2011-02-23 kinaba: { 23dfcca431 2011-02-23 kinaba: long[] g2 = new long[g.Length]; 23dfcca431 2011-02-23 kinaba: for(int i=s; i<g.Length; ++i) 23dfcca431 2011-02-23 kinaba: g2[i-s] = g[i]; 23dfcca431 2011-02-23 kinaba: for(int i=0; i<s; ++i) 23dfcca431 2011-02-23 kinaba: g2[i+g.Length-s] = g[i]; 23dfcca431 2011-02-23 kinaba: return g2; 23dfcca431 2011-02-23 kinaba: } 23dfcca431 2011-02-23 kinaba: }