結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
|
提出日時 | 2023-03-18 02:40:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 247 ms / 3,000 ms |
コード長 | 1,169 bytes |
コンパイル時間 | 709 ms |
コンパイル使用メモリ | 84,224 KB |
最終ジャッジ日時 | 2025-02-11 14:46:41 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <algorithm> #pragma GCC optimize("O2") using ll = long long int; using P = std::pair<ll, int>; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = (ll)(1e9+7); #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD); a += b; a = (a<MOD)?a:(a-MOD); } int a[225816],b[225816],cnt[225816]; std::vector<P> vec; int main(void){ int n,m,i,j=-1,flag=0; ll ans = INFLL; std::cin >> n; m = n*3; vec.reserve(m); for(i=0; i<n; ++i){ std::cin >> a[i]; } for(i=0; i<n; ++i){ std::cin >> b[i]; } for(i=0; i<n; ++i){ vec.push_back(P(a[i],i)); vec.push_back(P(b[i],i)); vec.push_back(P((a[i]+b[i])/2,i)); } std::sort(vec.begin(),vec.end()); for(i=0; i<m; ++i){ while(j<m && flag < n){ ++j; if(!cnt[vec[j].second]){ ++flag; } ++cnt[vec[j].second]; } if(j < m){ ans = std::min(ans,vec[j].first-vec[i].first); } --cnt[vec[i].second]; if(!cnt[vec[i].second]){ --flag; } } std::cout << ans << std::endl; return 0; }