-
Notifications
You must be signed in to change notification settings - Fork 3
/
D.cpp
47 lines (35 loc) · 919 Bytes
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
void work(){
int n;
cin >> n;
vector< int > d( n + 2 );
vector< pair < int, int > > ans;
for ( int i = 1; i <= n; i++ ) cin >> d [ i ];
int idx = 1;
int l = 1, r = n;
while( l <= r ) {
int x = d [ l ], y = d [ r ];
for ( int i = idx; i <= idx + x - 1; i++ ){
for ( int j = i + 1; j <= idx + y; j++){
ans.push_back( { i, j } );
}
}
idx += x;
for ( int i = l + 1; i < r; i++ ) d[i] -= x;
l++;
r--;
}
cout << ans.size() << '\n';
for ( auto [ u, v ] : ans ){
cout << u << " " << v << '\n';
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1; //cin >> T;
while(T--) work();
return 0;
}