public TAnswer Greedy(TSample Sample) { GreedyFloristSample sample = Sample as GreedyFloristSample; Int32 n = sample.n; Int32 k = sample.k; Int32[] c = sample.c; Int32 result = 0; Array.Sort(c); if (k >= n) { for (int i = 0; i < n; i++) { result += c[i]; } } else { for (int i = c.Length - 1; i >= 0; i--) { Int32 mult = (c.Length - 1 - i) / k + 1; result += mult * c[i]; } } return(new GreedyFloristAnswer() { result = result }); }
public override void CreateSamples(StreamReader reader) { string[] nk = reader.ReadLine().Split(' '); int n = Convert.ToInt32(nk[0]); int k = Convert.ToInt32(nk[1]); int[] c = Array.ConvertAll(reader.ReadLine().Split(' '), cTemp => Convert.ToInt32(cTemp)); GreedyFloristSample sample = new GreedyFloristSample() { c = c, k = k, n = n }; Samples.Add(sample); }