結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
|
提出日時 | 2023-03-21 13:30:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 117 ms / 3,000 ms |
コード長 | 1,088 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 177,540 KB |
実行使用メモリ | 13,192 KB |
最終ジャッジ日時 | 2024-09-18 14:20:10 |
合計ジャッジ時間 | 7,131 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;vector<int> a(n), b(n);for (int i = 0; i < n; i++) {cin >> a[i];}for (int i = 0; i < n; i++) {cin >> b[i];}vector<pair<int, int>> c;for (int i = 0; i < n; i++) {c.emplace_back(a[i], i);c.emplace_back(b[i], i);c.emplace_back(a[i] / 2 + b[i] / 2, i);}sort(c.begin(), c.end());vector<int> cnt(n, 0);int x = 0;int ans = 1e9;int L = 0, R = 0;while (R < 3 * n) {while (R < 3 * n && x < n) {if (cnt[c[R].second] == 0) {x++;}cnt[c[R].second]++;R++;}if (R == 3 * n && x < n) {break;}ans = min(ans, c[R - 1].first - c[L].first);cnt[c[L].second]--;if (cnt[c[L].second] == 0) {x--;}L++;if (L == R) {R++;}}cout << ans << '\n';}