結果

問題 No.808 Kaiten Sushi?
コンテスト
ユーザー noshi91
提出日時 2019-03-22 22:27:12
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 974 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 291 ms
コンパイル使用メモリ 61,696 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-07 12:44:40
合計ジャッジ時間 2,135 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<cstddef>
#include<cstdint>
#include<cstdio>
#include<limits>
#include<vector>

using isize = int;
using usize = unsigned int;
using u64 = unsigned long long;

int main() {
	usize N;
	u64 L;
	scanf("%u%llu", &N, &L);
	std::vector<u64> x(N);
	for (auto &e : x) {
		scanf("%llu", &e);
	}
	std::vector<u64> y(N);
	for (auto &e : y) {
		scanf("%llu", &e);
	}

	x.emplace_back(std::numeric_limits<u64>::max());
	y.emplace_back(std::numeric_limits<u64>::max());

	isize count = 0, max = 0, min = 0;
	auto xitr = x.cbegin(), yitr = y.cbegin();
	u64 last;
	for (usize i = 0;i != N * 2;++i) {
		if (*xitr < *yitr) {
			++count;
			if (max <= count) {
				max = count;
				last = *yitr;
			}
			++xitr;
		}
		else {
			--count;
			if (count <= min) {
				min = count;
			}
			++yitr;
		}
	}
	const usize diff = max - min;
	u64 ans;
	if (max == static_cast<isize>(0)) {
		ans = L*diff + y.front();
	}
	else {
		ans = L*diff - (L - last);
	}
	printf("%llu\n", ans);
	return 0;
}
0