“TŒ^90–β    ŽŸ‚Μ“TŒ^90–β‚Φ    ‘O‚Μ“TŒ^90–β‚Φ

“TŒ^90–β 034 There are few types of elementsiš4j


–β‘θ‚Φ‚ΜƒŠƒ“ƒN


C#‚Μƒ\[ƒX

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5 1");
            WillReturn.Add("1 2 3 4 5");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5 4");
            WillReturn.Add("1 1 2 4 2");
            //5
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("10 2");
            WillReturn.Add("1 2 3 4 4 3 2 1 2 3");
            //4
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = InputList[0].Split(' ').Select(pX => int.Parse(pX)).ToArray();
        int K = wkArr[1];

        int[] AArr = InputList[1].Split(' ').Select(pX => int.Parse(pX)).ToArray();
        int UB = AArr.GetUpperBound(0);

        var CntDict = new Dictionary<int, int>();

        var AnswerKouho = new List<int>();
        int R = 0;
        CntDict[AArr[0]] = 1;
        for (int L = 0; L <= UB; L++) {
            while (R + 1 <= UB && (CntDict.Count < K || CntDict.ContainsKey(AArr[R + 1]))) {
                R++;
                if (CntDict.ContainsKey(AArr[R]) == false) {
                    CntDict[AArr[R]] = 0;
                }
                CntDict[AArr[R]]++;
            }
            AnswerKouho.Add(R - L + 1);

            CntDict[AArr[L]]--;
            if (CntDict[AArr[L]] == 0) {
                CntDict.Remove(AArr[L]);
            }
        }
        Console.WriteLine(AnswerKouho.Max());
    }
}


‰πΰ

ŽΪŽζ–@‚Ε‰π‚’‚Δ‚ά‚·B