0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#1094. CSP提高组模拟赛T1【中山-2018.8.14A组-T1】区间

https://sjzezoj.com/submission/39138
This commit is contained in:
Baoshuo Ren 2021-10-17 16:10:32 +08:00 committed by Baoshuo Ren
parent 2ffc5e818c
commit 4cb3188f14
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

33
S2OJ/1094/1094.cpp Normal file
View File

@ -0,0 +1,33 @@
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
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;
}