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:
parent
2ffc5e818c
commit
4cb3188f14
33
S2OJ/1094/1094.cpp
Normal file
33
S2OJ/1094/1094.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user