Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <set>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<int> v(n);
- set<pair<int, int>> st;
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- st.insert(make_pair(v[i], i));
- sum += v[i] - 1;
- }
- if(sum >= n) {
- cout << "PROBLEM" << endl;
- return 0;
- }
- for(int i = 0; i < n; i++) {
- set<pair<int, int> >::iterator F = st.begin();
- set<pair<int, int> >::iterator L = st.end();
- L--;
- if(F->first > 0 and L->first > 0 and L->second != F->second) {
- cout << F->second + 1 << " " << L->second + 1 << endl;
- pair<int, int> p1 = *F;
- pair<int, int> p2 = *L;
- st.erase(F);
- st.erase(L);
- if(p1.first > 1) {
- st.insert(make_pair(p1.first - 1, p1.second));
- }
- if(p2.first > 1) {
- st.insert(make_pair(p2.first - 1, p2.second));
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement