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