結果
| 問題 |
No.2248 max(C)-min(C)
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2023-03-17 23:10:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 153 ms / 3,000 ms |
| コード長 | 1,189 bytes |
| コンパイル時間 | 1,598 ms |
| コンパイル使用メモリ | 181,136 KB |
| 実行使用メモリ | 18,172 KB |
| 最終ジャッジ日時 | 2024-09-18 12:15:27 |
| 合計ジャッジ時間 | 6,204 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<int,int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
int ma = 0, ans = INF;
priority_queue<asc(T)> pq;
vector<vector<int>> a(n,vector<int>(3));
rep(i,n) cin >> a[i][0];
rep(i,n){
cin >> a[i][2];
if(a[i][2]<a[i][0]) swap(a[i][2], a[i][0]);
a[i][1] = (a[i][0] + a[i][2]) / 2;
pq.push({a[i][0], i, 0});
chmax(ma, a[i][0]);
}
while(1){
int p,q,r;
tie(p,q,r) = pq.top();
pq.pop();
chmin(ans, ma-p);
if(r==2) break;
pq.push({a[q][r+1],q,r+1});
chmax(ma, a[q][r+1]);
}
cout << ans << '\n';
return 0;
}
houren