結果
| 問題 |
No.2248 max(C)-min(C)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-13 04:53:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 353 ms / 3,000 ms |
| コード長 | 1,588 bytes |
| コンパイル時間 | 1,804 ms |
| コンパイル使用メモリ | 199,864 KB |
| 最終ジャッジ日時 | 2025-02-11 10:48:37 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const double PI = 3.141592653589793;
bool cmp1(pll a, pll b) {
return a.first + a.second < b.first + b.second;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
vector<ll> A(N), B(N);
for (ll i = 0; i < N; ++i) {
cin >> A.at(i);
}
for (ll i = 0; i < N; ++i) {
cin >> B.at(i);
}
for (ll i = 0; i < N; ++i) {
if (A.at(i) > B.at(i)) {
swap(A.at(i), B.at(i));
}
}
if (N == 1) {
cout << 0 << "\n";
return 0;
}
multiset<pll> st;
for (ll i = 0; i < N; ++i) {
st.insert({A.at(i), i});
}
ll m = INF;
ll ans = (*st.rbegin()).first - min(m, ((*st.begin()).first));
while (!st.empty()) {
pll now = *st.begin();
st.erase(st.begin());
ll a = now.first, index = now.second;
if (a == B.at(index)) {
m = min(m, a);
}
else if (a * 2 == A.at(index) + B.at(index)) {
st.insert({B.at(index), index});
}
else {
st.insert({(A.at(index) + B.at(index)) / 2, index});
}
if (!st.empty()) {
ans = min(ans, (*st.rbegin()).first - min(m, ((*st.begin()).first)));
}
}
cout << ans << "\n";
}