From 12dbf98263b3bb72ba9364052ea298b6a0d5b861 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Mon, 4 Oct 2021 16:10:00 +0800 Subject: [PATCH] =?UTF-8?q?136.=20=E9=82=BB=E5=80=BC=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/8040990/ --- AcWing/136/136.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 AcWing/136/136.cpp diff --git a/AcWing/136/136.cpp b/AcWing/136/136.cpp new file mode 100644 index 00000000..3eb4e7d1 --- /dev/null +++ b/AcWing/136/136.cpp @@ -0,0 +1,27 @@ +#include + +using namespace std; + +int n, x; +set> s; + +int main() { + cin >> n; + s.insert({make_pair(INT_MIN, 0), make_pair(INT_MAX, 0)}); + for (int i = 1; i <= n; i++) { + cin >> x; + if (i > 1) { + auto it1 = s.upper_bound(make_pair(x, 0)); + auto it2 = it1--; + long long x1 = 0ll + x - it1->first; + long long x2 = 0ll + it2->first - x; + if (x1 <= x2) { + cout << x1 << ' ' << it1->second << endl; + } else { + cout << x2 << ' ' << it2->second << endl; + } + } + s.insert(make_pair(x, i)); + } + return 0; +}