using System; using System.Collections.Generic; using System.Text; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.GetInt(); int amebaCount = inpt[0]; int moveLen = inpt[1]; int maxStep = inpt[2]; inpt = Reader.GetInt(); for (int i = 0; i < inpt.Length; i++) { AmebaList.Add(new Ameba(inpt[i], inpt[i])); } for (int i = 0; i < maxStep; i++) { List nextList = new List(); foreach (Ameba am in AmebaList) { nextList.Add(am.Move(moveLen * -1)); nextList.Add(am); nextList.Add(am.Move(moveLen)); } nextList.Sort((a, b) => { if (a.From < b.From) { return -1; } if (a.From > b.From) { return 1; } if (a.To < b.To) { return -1; } if (a.To > b.To) { return 1; } return 0; }); for (int j = nextList.Count - 1; j >= 1; j--) { Ameba current = nextList[j]; Ameba before = nextList[j - 1]; if (current.From >= before.From && current.From <= before.To) { long newFrom = before.From; long newTo = Math.Max(before.To, current.To); Ameba newIns = new Ameba(newFrom, newTo); nextList[j - 1] = newIns; nextList.RemoveAt(j); } this.AmebaList = nextList; } } long ans = 0; foreach (Ameba am in this.AmebaList) { ans += (am.To - am.From + 1); } Console.WriteLine(ans.ToString("####################################################0")); } private List AmebaList = new List(); public class Ameba { public long From; public long To; public Ameba(long from, long to) { this.From = from; this.To = to; } public Ameba Move(int moveLen) { return new Ameba(this.From + moveLen, this.To + moveLen); } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 3 1 0 2 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }