結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
![]() |
提出日時 | 2024-04-09 12:41:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 366 ms / 3,000 ms |
コード長 | 1,288 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 209,212 KB |
最終ジャッジ日時 | 2025-02-20 23:19:58 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int n;cin >> n;vector<int> a(n), b(n);vector<vector<int>> c(n);for (int i = 0; i < n; i++) {cin >> a[i];}for (int i = 0; i < n; i++) {cin >> b[i];c[i].push_back(a[i]);c[i].push_back(b[i]);c[i].push_back((a[i] + b[i]) / 2);}const int INF = 2e9;vector<int> vals;priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;int ma = -INF;for (int i = 0; i < n; i++) {sort(c[i].begin(), c[i].end());for (int j : c[i]) {vals.push_back(j);}c[i].push_back(INF);pq.push({c[i][0], i});ma = max(ma, c[i][0]);}sort(vals.begin(), vals.end());vals.erase(unique(vals.begin(), vals.end()), vals.end());vector<int> idx(n, 0);int ans = INF;for (int mi : vals) {while (pq.top().first < mi) {int i = pq.top().second;pq.pop();idx[i]++;pq.push({c[i][idx[i]], i});ma = max(ma, c[i][idx[i]]);}ans = min(ans, ma - mi);}cout << ans << endl;}