func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > dis(100005), edge;   long long int cnt[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 0, n, e, x, y, z, i, j, k, g, q, ans = 0, sum = 0, c = 0, h;     cin >> n >> t;     for (i = 1; i <= n; i++) {       cin >> x;       dis[i].first = x;       dis[i].second = i;     }     sort(dis.begin() + 1, dis.begin() + n + 1);     if (dis[1].first != 0) {       cout <<  -1 n ;       return 0;     }     if (n == 1) {       cout <<  0 n ;       return 0;     }     if (dis[1].first == dis[2].first) {       cout <<  -1 n ;       return 0;     }     vector<long long int> v1, v2;     v1.push_back(dis[1].second);     i = 2;     long long int next = 1;     while (i <= n) {       for (j = i; j <= n; j++) {         if (dis[j].first != next) break;         v2.push_back(dis[j].second);       }       i = j;       long long int s1 = v1.size();       long long int s2 = v2.size();       for (j = 0, k = 0; j < s2 && k < s1;) {         if (cnt[v1[k]] == t) {           k++;           continue;         }         edge.push_back(make_pair(v1[k], v2[j]));         cnt[v1[k]]++;         cnt[v2[j]]++;         if (cnt[v1[k]] == t) k++;         j++;       }       if (j != s2) {         cout <<  -1 n ;         return 0;       }       v1.clear();       next++;       for (j = 0; j < s2; j++) {         v1.push_back(v2[j]);       }       v2.clear();     }     ans = edge.size();     cout << ans <<   n ;     for (i = 0; i < edge.size(); i++) {       cout << edge[i].first <<     << edge[i].second <<   n ;     }     return 0;   }   