AtCoderのABC    次のABCの問題へ    前のABCの問題へ

ABC189-C Mandarin Orange


問題へのリンク


C#のソース

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("6");
            WillReturn.Add("2 4 4 9 4 9");
            //20
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("6");
            WillReturn.Add("200 4 4 9 4 9");
            //200
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

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

        long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();

        long UB = AArr.GetUpperBound(0);

        long Answer = 0;
        for (long I = 0; I <= UB; I++) {
            long RangeMin = AArr[I];
            for (long J = I; J <= UB; J++) {
                RangeMin = Math.Min(RangeMin, AArr[J]);
                long AnswerKouho = RangeMin * (J - I + 1);
                Answer = Math.Max(Answer, AnswerKouho);
            }
        }
        Console.WriteLine(Answer);
    }
}


解説

O(N*N)で解いてます。