結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
|
提出日時 | 2023-03-17 22:01:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 476 ms / 3,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 740 ms |
コンパイル使用メモリ | 77,292 KB |
最終ジャッジ日時 | 2025-02-11 13:09:14 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#include <iostream> #include <set> using namespace std; typedef pair<int, int> P; int main() { int n; cin >> n; int a[200005], b[200005]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } set<P> st; for (int i = 0; i < n; i++) { if (a[i] > b[i]) { swap(a[i], b[i]); } st.insert(P(b[i], i)); } int ans = st.rbegin()->first - st.begin()->first; while (true) { P p = *st.rbegin(); st.erase(p); int i = p.second; if (p.first == a[i]) { break; } if (p.first == b[i]) { st.insert(P((a[i] + b[i]) / 2, i)); } else { st.insert(P(a[i], i)); } ans = min(ans, st.rbegin()->first - st.begin()->first); } cout << ans << endl; }