Advertisement
Josif_tepe

Untitled

Apr 13th, 2025
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     int n;
  10.     cin >> n;
  11.    
  12.     vector<int> v(n);
  13.     set<pair<int, int>> st;
  14.     int sum = 0;
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> v[i];
  17.         sum += v[i];
  18.        
  19.         st.insert(make_pair(v[i], i));
  20.     }
  21.     if(sum - n >= n) {
  22.         cout << "PROBLEM" << endl;
  23.         return 0;
  24.     }
  25.    
  26.     for(int i = 0; i < n; i++) {
  27.         auto F = st.begin();
  28.         auto E = st.end();
  29.         E--;
  30.        
  31.         if(F->first > 0 and E->first > 0 and E->second != F->second) {
  32.             cout << E->second + 1 << " " << F->second + 1 << endl;
  33.            
  34.             pair<int, int> tmp1 = *F, tmp2 = *E;
  35.             st.erase(F);
  36.             st.erase(E);
  37.            
  38.             tmp1.first--;
  39.             tmp2.first--;
  40.            
  41.             if(tmp1.first > 0) {
  42.                 st.insert(tmp1);
  43.             }
  44.             if(tmp2.first > 0) {
  45.                 st.insert(tmp2);
  46.             }
  47.         }
  48.     }
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement