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

T263082 区间(range)

https://www.luogu.com.cn/record/85504975
This commit is contained in:
Baoshuo Ren 2022-08-30 15:15:56 +08:00
parent 2ad54c40fb
commit 09be17a090
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 51 additions and 0 deletions

42
Luogu/T263082/T263082.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, a[N], b[N];
std::vector<std::pair<int, int>> ans;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i] - a[i - 1];
}
b[n + 1] = -a[n];
for (int i = 1, j = 1; i <= n + 1; i++) {
while (b[i] < 0) {
while (j < i && b[j] <= 0) j++;
b[j]--, b[i]++;
ans.emplace_back(j, i - 1);
}
}
cout << ans.size() << endl;
for (const auto &e : ans) {
cout << e.first << ' ' << e.second << endl;
}
return 0;
}

BIN
Luogu/T263082/samples/checker.cpp (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/T263082/samples/range.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/T263082/samples/range.out (Stored with Git LFS) Normal file

Binary file not shown.