static object Solve() { var(n, k) = Read2(); var s = Console.ReadLine(); var r = new List <char>(); var comp = Comparer2 <int> .Create(i => s[i], i => i); var set = new IndexedMultiSet <int>(comp); for (int i = 0; i < n - k; i++) { set.Add(i); } var t = -1; for (int i = n - k; i < n; i++) { set.Add(i); while (set.GetFirst() < t) { set.RemoveAt(0); } t = set.RemoveAt(0); r.Add(s[t]); } return(string.Join("", r)); }
public ImmutableArray <T> Sort(Comparison <T> comparison) { Requires.NotNull(comparison, nameof(comparison)); var self = this; return(self.Sort(Comparer2 <T> .Create(comparison))); }
public void Sort(Comparison <T> comparison) { Requires.NotNull(comparison, nameof(comparison)); if (Count > 1) { // Array.Sort does not have an overload that takes both bounds and a Comparison. // We could special case _count == _elements.Length in order to try to avoid // the IComparer allocation, but the Array.Sort overload that takes a Comparison // allocates such an IComparer internally, anyway. Array.Sort(_elements, 0, _count, Comparer2 <T> .Create(comparison)); } }
static void Main() { var n = int.Parse(Console.ReadLine()); var ss = Array.ConvertAll(new bool[n], _ => Console.ReadLine()); var comp = Comparer2 <string> .Create(s => s.TrimStart('0').Length, s => s.TrimStart('0'), s => - s.Length); var set = new IndexedMultiSet <string>(comp); foreach (var s in ss) { set.Add(s); } Console.WriteLine(string.Join("\n", set)); }