結果

問題 No.3325 陰陽師
コンテスト
ユーザー Rumain831
提出日時 2025-11-01 16:40:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,164 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 90,768 KB
実行使用メモリ 22,436 KB
最終ジャッジ日時 2025-11-01 16:40:39
合計ジャッジ時間 5,688 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
using ll = long long;

int f(vector<int> s, vector<int> t){
  multiset<int> stand;
  for(auto p:s) stand.insert(p);
  int m=t.size();
  for(int i=0; i<m; i++){
    auto p=stand.lower_bound(t[i]);
    if(p==stand.end()) return i;
    //cout << i << ' ' << *p << endl;
    stand.erase(p);
  }
  return m;
}

int main(void){
  int n, m; cin >> n >> m;
  vector<int> s(n), t(m);
  for(auto& p:s) cin >> p;
  for(auto& p:t) cin >> p;
  int maxi=f(s, t);
  //cout << maxi << endl;
  if(maxi==0){
    cout << 0 << endl; return 0;
  }
  vector<int> tt;
  for(int i=0; i<maxi; i++){
    tt.push_back(t[i]);
  }
  sort(tt.rbegin(), tt.rend());
  int left=-1e9-5, right=1e9;
  while(right-left>1){
    int mid=(left+right)/2;
    multiset<int> stand;
    for(auto p:s) stand.insert(p);
    bool ok=true;
    for(auto p:tt){
      auto q=stand.upper_bound(p+mid);
      if(q==stand.begin()){ok=false; break;}
      auto r=prev(q);
      if((*r)>=p) stand.erase(r);
      else{ok=false; break;}
    } 
    if(ok) right=mid;
    else left=mid;
  }
  cout << right << endl;
  return 0;
}
0