結果

問題 No.2408 Lakes and Fish
ユーザー pengin_2000pengin_2000
提出日時 2023-08-11 21:29:42
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 29,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 12:19:01
合計ジャッジ時間 2,198 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 54 ms
5,376 KB
testcase_05 AC 53 ms
5,376 KB
testcase_06 AC 54 ms
5,376 KB
testcase_07 AC 65 ms
5,376 KB
testcase_08 AC 62 ms
5,376 KB
testcase_09 AC 62 ms
5,376 KB
testcase_10 AC 62 ms
5,376 KB
testcase_11 AC 31 ms
5,376 KB
testcase_12 AC 44 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 25 ms
5,376 KB
testcase_15 AC 48 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 14 ms
5,376 KB
testcase_18 AC 29 ms
5,376 KB
testcase_19 AC 45 ms
5,376 KB
testcase_20 AC 42 ms
5,376 KB
testcase_21 AC 48 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int l[100005];
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int i;
	for (i = 0; i < n; i++)
		scanf("%lld", &l[i + 1]);
	l[n + 1] = 1e18;
	l[0] = -1e18;
	long long int ans = 0;
	long long int f, b, w, dist;
	long long int min, mid, max;
	for (i = 0; i < m; i++)
	{
		scanf("%lld %lld %lld", &f, &b, &w);
		min = -1;
		max = n + 1;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (l[mid] > f)
				max = mid;
			else
				min = mid;
		}
		dist = f - l[min];
		if (dist > l[max] - f)
			dist = l[max] - f;
		if (b > w - dist)
			ans += b;
		else
			ans += w - dist;
	}
	printf("%lld\n", ans);
	return 0;
}
0