Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- 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];
- sum += v[i];
- st.insert(make_pair(v[i], i));
- }
- if(sum - n >= n) {
- cout << "PROBLEM" << endl;
- return 0;
- }
- for(int i = 0; i < n; i++) {
- auto F = st.begin();
- auto E = st.end();
- E--;
- if(F->first > 0 and E->first > 0 and E->second != F->second) {
- cout << E->second + 1 << " " << F->second + 1 << endl;
- pair<int, int> tmp1 = *F, tmp2 = *E;
- st.erase(F);
- st.erase(E);
- tmp1.first--;
- tmp2.first--;
- if(tmp1.first > 0) {
- st.insert(tmp1);
- }
- if(tmp2.first > 0) {
- st.insert(tmp2);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement