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

ABC183-D Water Heater


問題へのリンク


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("4 10");
            WillReturn.Add("1 3 5");
            WillReturn.Add("2 4 4");
            WillReturn.Add("3 10 6");
            WillReturn.Add("2 4 1");
            //No
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4 10");
            WillReturn.Add("1 3 5");
            WillReturn.Add("2 4 4");
            WillReturn.Add("3 10 6");
            WillReturn.Add("2 3 1");
            //Yes
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6 1000000000");
            WillReturn.Add("0 200000 999999999");
            WillReturn.Add("2 20 1");
            WillReturn.Add("20 200 1");
            WillReturn.Add("200 2000 1");
            WillReturn.Add("2000 20000 1");
            WillReturn.Add("20000 200000 1");
            //Yes
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct UseInfoDef
    {
        internal long S;
        internal long T;
        internal long P;
    }

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

        long[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();

        SplitAct(InputList[0]);
        long W = wkArr[1];

        var UseInfoList = new List<UseInfoDef>();
        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            UseInfoDef WillAdd;
            WillAdd.S = wkArr[0];
            WillAdd.T = wkArr[1];
            WillAdd.P = wkArr[2];
            UseInfoList.Add(WillAdd);
        }

        long MaxT = UseInfoList.Max(pX => pX.T);
        long UB = MaxT;

        long[] RunSumArr = new long[UB + 1];

        foreach (UseInfoDef EachUseInfo in UseInfoList) {
            RunSumArr[EachUseInfo.S] += EachUseInfo.P;
            RunSumArr[EachUseInfo.T] -= EachUseInfo.P;
        }

        for (long I = 1; I <= UB; I++) {
            RunSumArr[I] += RunSumArr[I - 1];
        }

        long RunSumMax = RunSumArr.Max();

        Console.WriteLine(RunSumMax <= W ? "Yes" : "No");
    }
}


解説

いもす法で解いてます。