結果

問題 No.2408 Lakes and Fish
ユーザー bluemeganebluemegane
提出日時 2023-08-12 07:35:11
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,666 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 104,960 KB
実行使用メモリ 32,128 KB
最終ジャッジ日時 2024-04-29 22:03:24
合計ジャッジ時間 5,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
18,048 KB
testcase_01 AC 26 ms
17,792 KB
testcase_02 AC 25 ms
17,792 KB
testcase_03 AC 25 ms
18,048 KB
testcase_04 AC 202 ms
30,848 KB
testcase_05 AC 199 ms
30,976 KB
testcase_06 AC 195 ms
29,696 KB
testcase_07 AC 215 ms
32,128 KB
testcase_08 AC 216 ms
32,000 KB
testcase_09 AC 215 ms
32,000 KB
testcase_10 AC 218 ms
32,000 KB
testcase_11 AC 128 ms
25,472 KB
testcase_12 AC 164 ms
29,952 KB
testcase_13 AC 67 ms
24,576 KB
testcase_14 AC 108 ms
25,728 KB
testcase_15 AC 182 ms
29,056 KB
testcase_16 AC 82 ms
26,880 KB
testcase_17 AC 74 ms
23,680 KB
testcase_18 AC 119 ms
28,160 KB
testcase_19 AC 170 ms
27,008 KB
testcase_20 AC 168 ms
22,756 KB
testcase_21 AC 178 ms
27,776 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, m, a);
    }
    static void getAns(int n, int m, int[] a)
    {
        var ans = 0L;
        for (int i = 0; i < m; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var f = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            var w = int.Parse(line[2]);
            var p = LowerBound(a, f);
            if (p != n && a[p] == f) { ans += w; continue; }
            else ans += b;
            int c;
            if (p == n) c = f - a[n - 1];
            else if (p == 0) c = a[0] - f;
            else
            {
                var c1 = a[p] - f;
                var c2 = f - a[p - 1];
                c = Min(c1, c2);
            }
            ans += Max(0, w - b - c);
        }
        Console.WriteLine(ans);
    }
    static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        var low = start;
        var high = end;
        while (low < high)
        {
            var mid = (high + low) / 2;
            if (comparer.Compare(arr[mid], value) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    static int LowerBound<T>(T[] arr, T value) where T : IComparable
       => LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
0