Advertisement
Mirbek

Untitled

Mar 16th, 2022
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 2e5 + 5;
  6.  
  7. int n;
  8. int a[N], pos[N], used[N];
  9.  
  10. int main() {
  11.     cin >> n;
  12.  
  13.     for (int i = 1; i <= n; i++) {
  14.         cin >> a[i];
  15.         pos[i] = i;
  16.     }
  17.  
  18.     sort(pos + 1, pos + n + 1, [&](int i, int j) {
  19.             return (a[i] % 100) < (a[j] % 100);
  20.          });
  21.  
  22.     vector < pair <int, int> > pairs;
  23.  
  24.     long long t = 0;
  25.     int r = n, l = 1;
  26.     while (l < r) {
  27.         int s = (a[ pos[r] ] % 100) + (a[ pos[l] ] % 100);
  28.         if (s >= 100) {
  29.             pairs.push_back(make_pair(pos[l], pos[r]));
  30.             t += (a[ pos[r] ] + a[ pos[l] ]) / 100;
  31.             used[pos[l]] = used[pos[r]] = 1;
  32.             l++, r--;
  33.         } else {
  34.             l++;
  35.         }
  36.     }
  37.  
  38.     for (int i = 1; i <= n; i++) {
  39.         if (!used[i]) {
  40.             t += a[i] / 100;
  41.         }
  42.     }
  43.  
  44.     cout << t << endl;
  45.     cout << pairs.size() << endl;
  46.     for (int i = 0; i < pairs.size(); i++) {
  47.         cout << pairs[i].first << " " << pairs[i].second << endl;
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement