結果
問題 | No.808 Kaiten Sushi? |
ユーザー |
|
提出日時 | 2019-03-22 22:45:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 976 bytes |
コンパイル時間 | 756 ms |
コンパイル使用メモリ | 82,660 KB |
実行使用メモリ | 23,808 KB |
最終ジャッジ日時 | 2024-09-19 06:09:17 |
合計ジャッジ時間 | 8,153 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 WA * 17 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> using namespace std; int main() { int N; long long L; cin >> N >> L; vector<long long> A(N), B(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; set<long long> a, b; for (int i = 0; i < N; i++) { a.insert(A[i]); a.insert(A[i] + L); b.insert(B[i]); b.insert(B[i] + L); } long long ans = 0; long long x = 0; for (int i = 0; i < N; i++) { { auto it = b.lower_bound(x); auto it2 = prev(a.lower_bound(*it)); ans += *it2 - x; x = *it2 % L; a.erase(x); a.erase(x + L); } { if (!a.empty()) { auto it = a.lower_bound(x); auto it2 = prev(b.lower_bound(*it)); ans += *it2 - x; x = *it2 % L; b.erase(x); b.erase(x + L); } else { ans += *b.lower_bound(x) - x; } } } cout << ans << '\n'; }