結果

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

ソースコード

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;
  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> S=stand;
    bool ok=true;
    for(auto p:tt){
      auto q=S.upper_bound(p+mid);
      if(q==S.begin()){ok=false; break;}
      auto r=prev(q);
      if((*r)>=p) S.erase(r);
      else{ok=false; break;}
    } 
    if(ok) right=mid;
    else left=mid;
  }
  cout << right << endl;
  return 0;
}
0