Exemplo n.º 1
0
    public static void Main()
    {
        var nmkq = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n    = nmkq[0];
        var m    = nmkq[1];
        var k    = nmkq[2];
        var q    = nmkq[3];

        int[][] mat = Enumerable.Repeat(0, n).Select(_ => Enumerable.Repeat(int.MaxValue / 2, m).ToArray()).ToArray();

        for (int i = 0; i < q; i++)
        {
            var xyt = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var x   = xyt[0] - 1;
            var y   = xyt[1] - 1;
            var t   = xyt[2];
            mat[x][y] = t;
        }


        FoldableQueue <int>[] fqueues = Enumerable.Repeat(0, n).Select(_ => new FoldableQueue <int>(Max)).ToArray();

        int res = int.MaxValue / 2;

        for (int j = 0; j < m; j++)
        {
            FoldableQueue <int> fqueue = new FoldableQueue <int>(Max);
            for (int i = 0; i < n; i++)
            {
                fqueues[i].Push(mat[i][j]);
                if (fqueues[i].Count == k)
                {
                    fqueue.Push(fqueues[i].Value);
                    fqueues[i].Pop();
                }
                if (fqueue.Count == k)
                {
                    res = Min(res, fqueue.Value);
                    fqueue.Pop();
                }
            }
        }

        if (res == int.MaxValue / 2)
        {
            res = -1;
        }
        Console.WriteLine(res);
    }
Exemplo n.º 2
0
    static void Solve()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        bool Validate(int[] a)
        {
            return(a.Min() == 1 && a.Max() == a.Length && a.Distinct().Count() == a.Length);
        }

        int valid   = n + 1;
        int invalid = 1;

        while (valid - invalid > 1)
        {
            var mid = (invalid + valid) / 2;

            var cnt = n - mid + 1;
            var seq = new int[cnt];
            FoldableQueue <int> fQueue = new FoldableQueue <int>(Min);
            for (int i = 0; i < mid - 1; i++)
            {
                fQueue.Push(a[i]);
            }
            for (int i = 0; i < seq.Length; i++)
            {
                fQueue.Push(a[i + mid - 1]);
                seq[i] = fQueue.Value;
                fQueue.Pop();
            }

            if (Validate(seq))
            {
                valid = mid;
            }
            else
            {
                invalid = mid;
            }
        }
        char[] res = new char[n];
        res[0] = Validate(a) ? '1' : '0';
        for (int i = 1; i < n; i++)
        {
            res[i] = valid <= i + 1 ? '1' : '0';
        }
        Console.WriteLine(res);
    }