typoする毎日

中小いっと企業にいながら、サークル的なやつをやってる人の備忘録

paizaオンラインハッカソン 4Lite

コードを書いて転職するでおなじみのpaizaが、オンラインハッカソンのイベントを行ってますね。

マンガ版「エンジニアでも恋がしたい!」〜転職初日にぶつかった女の子が同僚だった件〜|paizaオンラインハッカソン4 Lite


というわけで、僕もさっそうと参戦しますた。

言語はめんどっちかったんでC#で。

全部で3問だったので、適当に載せときます。

[Q1]

class Program
{
    static void Main(string[] args)
    {
        // n 
        int n = int.Parse(System.Console.ReadLine().ToString());

        // 各在庫数
        int stockcount = 0;
        for (int i = 0; i < n; i++)
        stockcount += int.Parse(System.Console.ReadLine().ToString());

        Console.WriteLine(stockcount);

    }
}


[Q2]

class Program
{
    static void Main(string[] args)
    {
        // n 
        int n = int.Parse(System.Console.ReadLine().ToString());

        // 1カラム目=必要在庫数
        // 2カラム目=現在の在庫数
        // 3カラム目=価格
        long price = 0;
        for (int i = 0; i < n; i++)
        {
            int[] input = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

            // 現在の在庫数が足らない場合
            if (input[0] > input[1])
                price += (input[0] - input[1]) * input[2];
        }
        Console.WriteLine(price);
    }
}


[Q3]

class Program
{
    static void Main(string[] args)
    {
        // 1行目に区間の長さ t と コマの総数 n がスペース区切り  
        int[] lencount = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

        int[] checkbuf = new int[lencount[1]];
        int i = 0;
        for (i = 0; i < lencount[1]; i++)
            checkbuf[i] = int.Parse(Console.ReadLine());

        // 計算

        // 最大値
        int max = 0;
        // 格納
        int tmp = 0;
        for (i = 0; i < lencount[1]; i++)
        {
            if (i < lencount[0])
                tmp += checkbuf[i];
            else
                tmp = tmp - checkbuf[i - lencount[0]] + checkbuf[i];

            max = max < tmp ? tmp : max;
        }

        Console.WriteLine(max);
    }
}