public void LowerBoundTest()
        {
            var tree = new RandomizedBinarySearchTree <int>();

            tree.Insert(0);
            tree.Insert(1);
            tree.Insert(-1);
            tree.Insert(2);
            tree.Insert(-2);

            Assert.That(tree.LowerBound(-3), Is.EqualTo(0));
            Assert.That(tree.LowerBound(-2), Is.EqualTo(0));
            Assert.That(tree.LowerBound(-1), Is.EqualTo(1));
            Assert.That(tree.LowerBound(0), Is.EqualTo(2));
            Assert.That(tree.LowerBound(1), Is.EqualTo(3));
            Assert.That(tree.LowerBound(2), Is.EqualTo(4));
            Assert.That(tree.LowerBound(3), Is.EqualTo(5));
        }
Exemplo n.º 2
0
        public static void Solve()
        {
            var(N, M) = Scanner.Scan <int, int>();
            var A = Scanner.ScanEnumerable <int>().ToArray();
            var B = Scanner.ScanEnumerable <int>().ToArray();
            var C = Scanner.ScanEnumerable <int>().ToArray();
            var D = Scanner.ScanEnumerable <int>().ToArray();

            var chocos = A.Zip(B).Select(x => new Element(0, x.First, x.Second));
            var cases  = C.Zip(D).Select(x => new Element(1, x.First, x.Second));
            var list   = chocos.Concat(cases).ToList();

            list.Sort((x, y) =>
            {
                var result = y.H.CompareTo(x.H);
                return(result != 0 ? result : y.Type.CompareTo(x.Type));
            });

            var set = new RandomizedBinarySearchTree <int>();

            foreach (var e in list)
            {
                if (e.Type == 0)
                {
                    var lb = set.LowerBound(e.W);
                    if (lb < 0 || set.Count <= lb)
                    {
                        Console.WriteLine("No");
                        return;
                    }

                    set.RemoveAt(lb);
                }
                else
                {
                    set.Insert(e.W);
                }
            }

            Console.WriteLine("Yes");
        }