using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int monsterCount = int.Parse(Reader.ReadLine()); int[] mikataArr = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int[] tekiArr = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int max = int.MaxValue; for (int i = 0; i < monsterCount; i++) { SortedDictionary mikata = new SortedDictionary(); mikataArr.ToList().ForEach(a=>mikata.Add(new Monster(mikata.Count, a), true)); int subMax = 0; bool mustBreak = false; for (int j = 0; j < monsterCount; j++) { Monster m = mikata.First().Key; mikata.Remove(m); m.Level += tekiArr[(i+j)%monsterCount] / 2; m.BattleCount++; subMax = Math.Max(subMax, m.BattleCount); mikata.Add(m, true); if(subMax >= max) { mustBreak = true; break; } } if(mustBreak) { continue; } max = Math.Min(max, subMax); } Console.WriteLine(max); } private class Monster : IComparable, IEquatable { public int Level; public int BattleCount; public int ID; public int CompareTo(object obj) { Monster mns = (Monster)obj; if (this.Level == mns.Level) { if(this.BattleCount == mns.BattleCount) { return this.ID.CompareTo(mns.ID); } return this.BattleCount.CompareTo(mns.BattleCount); } return this.Level.CompareTo(mns.Level); } public Monster(int id, int level) { this.Level = level; this.BattleCount = 0; this.ID = id; } public bool Equals(Monster obj) { return obj.ID == this.ID; } } public class Reader { private static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 69 3253 3369 660 1949 4617 3586 3561 3382 7928 4932 2034 599 7713 1984 4040 5308 7972 6853 6802 5811 2226 4349 1997 4202 195 6608 1785 823 1084 2947 6118 4671 5526 4139 7016 3932 6534 1867 935 4629 4405 67 4014 1322 3329 4949 4990 2086 4517 897 6712 6512 4017 2083 7666 2190 4897 6482 7590 2197 7370 2163 6238 5317 6435 5041 5513 2275 4978 3003 1579 6252 1970 1595 2763 3275 5453 2496 6143 4733 589 1886 6384 3295 1223 3714 2426 5626 149 1848 3978 6608 6489 2454 106 2197 2982 4055 1239 7266 1774 329 6684 1063 7593 5659 7697 6475 815 1606 7363 35 5780 3853 3072 7709 7822 1902 7030 6723 5812 7640 3297 6286 3634 123 7996 7811 5854 4299 885 310 1943 3064 7146 897 3778 6973 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }