From 4cb3188f14a3e56c3bfb8e6bfacd2c8bec376031 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 17 Oct 2021 16:10:32 +0800 Subject: [PATCH] =?UTF-8?q?#1094.=20CSP=E6=8F=90=E9=AB=98=E7=BB=84?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E8=B5=9BT1=E3=80=90=E4=B8=AD=E5=B1=B1-2018.8?= =?UTF-8?q?.14A=E7=BB=84-T1=E3=80=91=E5=8C=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/39138 --- S2OJ/1094/1094.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 S2OJ/1094/1094.cpp diff --git a/S2OJ/1094/1094.cpp b/S2OJ/1094/1094.cpp new file mode 100644 index 00000000..63c3d77e --- /dev/null +++ b/S2OJ/1094/1094.cpp @@ -0,0 +1,33 @@ +#pragma GCC optimize("Ofast") + +#include + +using namespace std; + +int n, a[100005], d[100005], ans; + +int main() { + scanf("%d", &n); + for (int i = 1; i <= n; i++) { + scanf("%d", a + i); + } + for (int i = 1; i <= n; i++) { + d[i] = a[i] - a[i - 1]; + if (d[i] > 0) ans += d[i]; + } + d[0] = INT_MAX; + d[n + 1] = INT_MIN; + printf("%d\n", ans); + for (int i = 1, t = 2; i <= n; i++) { + while (d[i]) { + if (d[t] >= 0) { + t++; + } else { + d[i]--; + d[t]++; + printf("%d %d\n", i, t - 1); + } + } + } + return 0; +}