Hex Artifact Content
Not logged in

Artifact 2cc6fccce968278db4b1135aeb38298c7014b650:


0000: 75 73 69 6e 67 20 53 79 73 74 65 6d 3b 0a 75 73  using System;.us
0010: 69 6e 67 20 53 79 73 74 65 6d 2e 4c 69 6e 71 3b  ing System.Linq;
0020: 0a 0a 63 6c 61 73 73 20 43 0a 7b 0a 09 73 74 61  ..class C.{..sta
0030: 74 69 63 20 76 6f 69 64 20 4d 61 69 6e 28 29 0a  tic void Main().
0040: 09 7b 0a 09 09 6c 6f 6e 67 5b 5d 20 54 73 20 3d  .{...long[] Ts =
0050: 20 72 65 61 64 4c 6f 6e 67 41 72 72 61 79 28 29   readLongArray()
0060: 3b 0a 09 09 6c 6f 6e 67 20 20 20 54 20 20 3d 20  ;...long   T  = 
0070: 54 73 5b 30 5d 3b 0a 0a 09 09 66 6f 72 28 6c 6f  Ts[0];....for(lo
0080: 6e 67 20 43 3d 31 3b 20 43 3c 3d 54 3b 20 2b 2b  ng C=1; C<=T; ++
0090: 43 29 0a 09 09 7b 0a 09 09 09 6c 6f 6e 67 5b 5d  C)...{....long[]
00a0: 20 52 6b 4e 20 3d 20 72 65 61 64 4c 6f 6e 67 41   RkN = readLongA
00b0: 72 72 61 79 28 29 3b 0a 09 09 09 6c 6f 6e 67 20  rray();....long 
00c0: 20 20 52 20 3d 20 52 6b 4e 5b 30 5d 3b 0a 09 09    R = RkN[0];...
00d0: 09 6c 6f 6e 67 20 20 20 6b 20 3d 20 52 6b 4e 5b  .long   k = RkN[
00e0: 31 5d 3b 0a 09 09 09 6c 6f 6e 67 20 20 20 4e 20  1];....long   N 
00f0: 3d 20 52 6b 4e 5b 32 5d 3b 0a 09 09 09 6c 6f 6e  = RkN[2];....lon
0100: 67 5b 5d 20 67 20 3d 20 72 65 61 64 4c 6f 6e 67  g[] g = readLong
0110: 41 72 72 61 79 28 29 3b 0a 0a 09 09 09 43 6f 6e  Array();.....Con
0120: 73 6f 6c 65 2e 57 72 69 74 65 4c 69 6e 65 28 22  sole.WriteLine("
0130: 43 61 73 65 20 23 7b 30 7d 3a 20 7b 31 7d 22 2c  Case #{0}: {1}",
0140: 20 43 2c 20 73 6f 6c 76 65 53 6d 61 6c 6c 28 52   C, solveSmall(R
0150: 2c 6b 2c 4e 2c 67 29 29 3b 0a 09 09 7d 0a 09 7d  ,k,N,g));...}..}
0160: 0a 0a 09 73 74 61 74 69 63 20 6c 6f 6e 67 5b 5d  ...static long[]
0170: 20 72 65 61 64 4c 6f 6e 67 41 72 72 61 79 28 29   readLongArray()
0180: 0a 09 7b 0a 09 09 72 65 74 75 72 6e 20 28 66 72  ..{...return (fr
0190: 6f 6d 20 73 20 69 6e 20 43 6f 6e 73 6f 6c 65 2e  om s in Console.
01a0: 52 65 61 64 4c 69 6e 65 28 29 2e 53 70 6c 69 74  ReadLine().Split
01b0: 28 27 20 27 29 20 73 65 6c 65 63 74 20 6c 6f 6e  (' ') select lon
01c0: 67 2e 50 61 72 73 65 28 73 29 29 2e 54 6f 41 72  g.Parse(s)).ToAr
01d0: 72 61 79 28 29 3b 0a 09 7d 0a 0a 09 73 74 61 74  ray();..}...stat
01e0: 69 63 20 6c 6f 6e 67 20 73 6f 6c 76 65 53 6d 61  ic long solveSma
01f0: 6c 6c 28 6c 6f 6e 67 20 52 2c 20 6c 6f 6e 67 20  ll(long R, long 
0200: 6b 2c 20 6c 6f 6e 67 20 4e 2c 20 6c 6f 6e 67 5b  k, long N, long[
0210: 5d 20 67 29 0a 09 7b 0a 09 09 6c 6f 6e 67 20 74  ] g)..{...long t
0220: 6f 74 61 6c 45 61 72 6e 20 3d 20 30 3b 0a 0a 09  otalEarn = 0;...
0230: 09 66 6f 72 28 69 6e 74 20 69 3d 30 3b 20 69 3c  .for(int i=0; i<
0240: 52 3b 20 2b 2b 69 29 0a 09 09 7b 0a 09 09 09 6c  R; ++i)...{....l
0250: 6f 6e 67 20 72 69 64 65 20 3d 20 30 3b 0a 09 09  ong ride = 0;...
0260: 09 66 6f 72 28 69 6e 74 20 71 3d 30 3b 20 71 3c  .for(int q=0; q<
0270: 67 2e 4c 65 6e 67 74 68 3b 20 2b 2b 71 29 0a 09  g.Length; ++q)..
0280: 09 09 09 69 66 28 20 72 69 64 65 20 2b 20 67 5b  ...if( ride + g[
0290: 71 5d 20 3e 20 6b 20 29 0a 09 09 09 09 7b 0a 09  q] > k ).....{..
02a0: 09 09 09 09 67 20 3d 20 72 6f 74 61 74 65 28 67  ....g = rotate(g
02b0: 2c 20 71 29 3b 0a 09 09 09 09 09 62 72 65 61 6b  , q);......break
02c0: 3b 0a 09 09 09 09 7d 0a 09 09 09 09 65 6c 73 65  ;.....}.....else
02d0: 0a 09 09 09 09 7b 0a 09 09 09 09 09 72 69 64 65  .....{......ride
02e0: 20 2b 3d 20 67 5b 71 5d 3b 0a 09 09 09 09 7d 0a   += g[q];.....}.
02f0: 09 09 09 74 6f 74 61 6c 45 61 72 6e 20 2b 3d 20  ...totalEarn += 
0300: 72 69 64 65 3b 0a 09 09 7d 0a 0a 09 09 72 65 74  ride;...}....ret
0310: 75 72 6e 20 74 6f 74 61 6c 45 61 72 6e 3b 0a 09  urn totalEarn;..
0320: 7d 0a 0a 09 73 74 61 74 69 63 20 6c 6f 6e 67 5b  }...static long[
0330: 5d 20 72 6f 74 61 74 65 28 6c 6f 6e 67 5b 5d 20  ] rotate(long[] 
0340: 67 2c 20 69 6e 74 20 73 29 0a 09 7b 0a 09 09 6c  g, int s)..{...l
0350: 6f 6e 67 5b 5d 20 67 32 20 3d 20 6e 65 77 20 6c  ong[] g2 = new l
0360: 6f 6e 67 5b 67 2e 4c 65 6e 67 74 68 5d 3b 0a 09  ong[g.Length];..
0370: 09 66 6f 72 28 69 6e 74 20 69 3d 73 3b 20 69 3c  .for(int i=s; i<
0380: 67 2e 4c 65 6e 67 74 68 3b 20 2b 2b 69 29 0a 09  g.Length; ++i)..
0390: 09 09 67 32 5b 69 2d 73 5d 20 3d 20 67 5b 69 5d  ..g2[i-s] = g[i]
03a0: 3b 0a 09 09 66 6f 72 28 69 6e 74 20 69 3d 30 3b  ;...for(int i=0;
03b0: 20 69 3c 73 3b 20 2b 2b 69 29 0a 09 09 09 67 32   i<s; ++i)....g2
03c0: 5b 69 2b 67 2e 4c 65 6e 67 74 68 2d 73 5d 20 3d  [i+g.Length-s] =
03d0: 20 67 5b 69 5d 3b 0a 09 09 72 65 74 75 72 6e 20   g[i];...return 
03e0: 67 32 3b 0a 09 7d 0a 7d 0a                       g2;..}.}.