結果
| 問題 |
No.808 Kaiten Sushi?
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2019-03-22 22:10:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 248 ms / 2,000 ms |
| コード長 | 3,067 bytes |
| コンパイル時間 | 703 ms |
| コンパイル使用メモリ | 93,324 KB |
| 実行使用メモリ | 12,800 KB |
| 最終ジャッジ日時 | 2024-09-19 05:42:25 |
| 合計ジャッジ時間 | 6,484 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
vector<vector<pair<int,ll> > > g;
int main(){
int n;
ll L;
cin >> n >> L;
set<ll> st,st2;
rep(i,n){
ll a;
cin >> a;
st.insert(a);
}
rep(i,n){
ll a;
cin >> a;
st2.insert(a);
}
ll ans = 0;
ll now = 0;
bool flag = 0;
while(st2.size()>0){
if(!flag){
auto p = st.lower_bound(now);
ll next,next2;
if(p==st.end()){
next = *st.begin();
}else{
next = *p;
}
auto q = st2.lower_bound(next);
ll goal;
if(q==st2.end()){
next2 = *st2.begin();
auto pp = st.lower_bound(next2);
if(pp==st.begin()){
pp = st.end();
pp--;
goal = *pp;
}else{
pp--;
goal = *pp;
}
}else{
next2 = *q;
auto pp = st.lower_bound(next2);
pp--;
goal = *pp;
}
if(now<goal){
ans += goal-now;
}else{
ans += goal+L-now;
}
st.erase(goal);
now = goal;
flag = 1;
}else{
auto p = st2.lower_bound(now);
ll next,next2;
if(p==st2.end()){
next = *st2.begin();
}else{
next = *p;
}
auto q = st.lower_bound(next);
ll goal;
if(q==st.end()){
next2 = *st.begin();
auto pp = st2.lower_bound(next2);
if(pp==st2.begin()){
pp = st2.end();
pp--;
goal = *pp;
}else{
pp--;
goal = *pp;
}
}else{
next2 = *q;
auto pp = st2.lower_bound(next2);
pp--;
goal = *pp;
}
if(now<goal){
ans += goal-now;
}else{
ans += goal+L-now;
}
st2.erase(goal);
now = goal;
flag = 0;
}
// for(auto x:st){
// cerr << x << " ";
// }
// cerr << endl;
// for(auto x:st2){
// cerr << x << " ";
// }
// cerr << endl;
}
cout << ans << endl;
return 0;
}
mtsd