結果

問題 No.3325 陰陽師
コンテスト
ユーザー Rumain831
提出日時 2025-11-01 16:51:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 558 ms / 2,000 ms
コード長 1,194 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 93,056 KB
実行使用メモリ 25,088 KB
最終ジャッジ日時 2025-11-01 16:52:03
合計ジャッジ時間 13,578 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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);
  multiset<int> stand;
  for(auto& p:s) cin >> p, stand.insert(p);
  for(auto& p:t) cin >> p;
  int maxi=f(s, t);
  //cout << maxi << endl;
  sort(s.begin(), s.end());
  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, id=n-1;
    bool ok=true;
    for(int i=0; i<maxi; i++){
      int p=tt[i];
      while(id>=0&&s[id]>p+mid){
        id--;
      }
      if(id<0||s[id]<p){ok=false; break;}
      id--;
      if(id<0&&i!=maxi-1){ok=false; break;}
    } 
    if(ok) right=mid;
    else left=mid;
  }
  cout << right << endl;
  return 0;
}
0