結果
問題 |
No.2248 max(C)-min(C)
|
ユーザー |
|
提出日時 | 2023-07-12 22:11:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,638 bytes |
コンパイル時間 | 1,246 ms |
コンパイル使用メモリ | 111,672 KB |
最終ジャッジ日時 | 2025-02-15 10:07:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | RE * 51 |
ソースコード
#include<iostream> #include<set> #include<algorithm> #include<vector> #include<string> #include<set> #include<map> #include<numeric> #include<queue> #include<cmath> using namespace std; typedef long long ll; const int INF=1<<30; typedef pair<int,int> P; typedef pair<int,P> PP; const ll MOD=998244353; const double PI=acos(-1); int main(){ int N; cin>>N; vector<int> A(N),B(N); for(int i=0;i<N;i++){ cin>>A[i]; } for(int i=0;i<N;i++){ cin>>B[i]; } vector<vector<int>> C(5,vector<int>(N)); for(int i=0;i<N;i++){ if(A[i]>B[i]) swap(A[i],B[i]); //A[i]<=B[i] } for(int i=0;i<N;i++){ C[i][0]=-INF; C[i][1]=A[i]; C[i][2]=(A[i]+B[i])/2; C[i][3]=B[i]; C[i][4]=INF; } vector<int> mini; for(int i=0;i<N;i++){ for(int j=1;j<=3;j++){ mini.push_back(C[i][j]); } } sort(mini.begin(),mini.end());//C[i][j]が小さい順に priority_queue<PP,vector<PP>,greater<PP>> pq; for(int i=0;i<N;i++){ //C[i][0]の値(-INF), index, 次に見るべきインデックス pq.emplace(make_pair(C[i][0],make_pair(i,0))); } int ans=INF; int nowmaxi=-INF; for(int e:mini){//C[i][j]が小さい順 int nowmini=e; while(!pq.empty() && pq.top().first< nowmini){ auto [v,p]=pq.top(); pq.pop(); p.second++; v=C[p.first][p.second]; pq.push(make_pair(v,p)); nowmaxi=max(nowmaxi,v); } ans=min(ans,nowmaxi-nowmini); } cout<<ans<<endl; }