fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n,x,t=0,c = 0; cin >> n;
  6. vector<pair<int,int>> s;
  7. for(int i=0;i<n;i++){
  8. cin >> x;
  9. s.push_back({x,i+1});
  10. //cout << x << " " << i+1 << endl;
  11. }
  12. sort(s.begin(),s.end(),greater<>());
  13. for(auto it = s.begin();it != s.end();++it){
  14. t += it->first * c + 1;
  15. ++c;
  16. }
  17. cout << t << endl;
  18. for(auto it = s.begin();it != s.end();++it) cout << it->second << " ";
  19. return 0;
  20. }
Success #stdin #stdout 0s 5288KB
stdin
3
20 10 20

stdout
43
3 1 2