#include<iostream> #include<algorithm> using namespace std; const int ene = 1e6+10; int t[ene]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { int a; cin >> a; a--; t[i] = a; } sort(t,t+n); int zera = 0; int kraw = 0; for(int i = 0; i < n; i++) { if(t[i] == 0)zera++; kraw+=t[i]; if(kraw == i-1 && i>=2) { cout << 0 << "\n"; cout << i+1 << "\n"; int k = i-1; t[i]++; for(int j = i; j >= 0; j--) { for(int h = 0; h < t[j]; h++) { cout << j+1 << " " << k+1 << "\n"; k--; } } return 0; } if(kraw > i-1 && i>= 2) { cout << 1 << "\n" << i+1 << "\n"; t[i]-=(kraw-i+1); int k = i-1; t[i]++; for(int j = i; j >= 0; j--) { for(int h = 0; h < t[j]; h++) { cout << j+1 << " " << k+1 << "\n"; k--; } } return 0; } } return 0; }
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include<iostream> #include<algorithm> using namespace std; const int ene = 1e6+10; int t[ene]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { int a; cin >> a; a--; t[i] = a; } sort(t,t+n); int zera = 0; int kraw = 0; for(int i = 0; i < n; i++) { if(t[i] == 0)zera++; kraw+=t[i]; if(kraw == i-1 && i>=2) { cout << 0 << "\n"; cout << i+1 << "\n"; int k = i-1; t[i]++; for(int j = i; j >= 0; j--) { for(int h = 0; h < t[j]; h++) { cout << j+1 << " " << k+1 << "\n"; k--; } } return 0; } if(kraw > i-1 && i>= 2) { cout << 1 << "\n" << i+1 << "\n"; t[i]-=(kraw-i+1); int k = i-1; t[i]++; for(int j = i; j >= 0; j--) { for(int h = 0; h < t[j]; h++) { cout << j+1 << " " << k+1 << "\n"; k--; } } return 0; } } return 0; } |