Advertisement
Anwar_Rizk

Untitled

May 2nd, 2024
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using db = double;
  3. using ll = long long;
  4. using ld = long double;
  5. #define ss s.size()
  6. #define ss_s sort(s.begin(), s.end())
  7. using namespace std;
  8.  
  9. void FastIO()
  10. {
  11.     ios::sync_with_stdio(false);
  12.     cin.tie(NULL);
  13.     cout.tie(NULL);
  14.  
  15. #ifndef ONLINE_JUDGE
  16.     freopen("input.txt", "r", stdin);
  17.     freopen("output.txt", "w", stdout);
  18.     freopen("error.txt", "w", stderr);
  19. #endif
  20. }
  21.  
  22. bool comp(pair<int, int> a, pair<int, int> b)
  23. {
  24.     if (a.first == b.first)
  25.         return a.second < b.second;
  26.     return a.first > b.first;
  27. }
  28.  
  29. int main()
  30. {
  31.     FastIO();
  32.     int num, sum = 0;
  33.     cin >> num;
  34.     pair<int, int> arr[num];
  35.     for (ll i = 0; i < num; i++)
  36.     {
  37.         cin >> arr[i].first;
  38.         arr[i].second = i + 1;
  39.     }
  40.     sort(arr, arr + num, comp);
  41.     for (ll i = 0; i < num; i++)
  42.     {
  43.         sum += ((arr[i].first * i) + 1);
  44.     }
  45.     cout << sum << endl;
  46.     for (ll i = 0; i < num; i++)
  47.     {
  48.         cout << arr[i].second << " ";
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement