結果
| 問題 |
No.2408 Lakes and Fish
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2023-08-12 07:35:11 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 220 ms / 2,000 ms |
| コード長 | 1,666 bytes |
| コンパイル時間 | 942 ms |
| コンパイル使用メモリ | 114,252 KB |
| 実行使用メモリ | 39,916 KB |
| 最終ジャッジ日時 | 2024-11-19 06:28:28 |
| 合計ジャッジ時間 | 6,246 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
bluemegane