結果

問題 No.1722 [Cherry 3rd Tune C] In my way
ユーザー bluemegane
提出日時 2021-10-29 22:31:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,263 bytes
コンパイル時間 3,261 ms
コンパイル使用メモリ 104,576 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-10-07 12:07:55
合計ジャッジ時間 2,692 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var m = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var x = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var y = Array.ConvertAll(line, int.Parse);
        getAns(m, x, y);
    }
    static void getAns(int m, int[] x, int[] y)
    {
        Array.Sort(y);
        foreach (var a in x)
        {
            var p = LowerBound<int>(y, a);
            if (p == m) Console.WriteLine("Infinity");
            else Console.WriteLine(y[p] - a);
        }
    }
    public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int LowerBound<T>(T[] arr, T value) where T : IComparable
    {
        return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}
0