# c

May 27th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include<bits/stdc++.h>
2. #include<iostream>
3. #include<cmath>
4. #include<iomanip>
5. #include<algorithm>
6. #include<cstdlib>
7. #include<cstring>
8. #include<vector>
9. #include<utility>
10. using namespace std;
11.
12. #define ll long long
13. #define nl '\n'
14. #define sz(x) int(x.size())
15. #define all(x) x.begin(),x.end()
16. #define rall(s)  s.rbegin(), s.rend()
17. #define getline(s) getline(cin>>ws,s)
18. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
19. #define pi  3.141592653589793
20.
21.
22.
23.
24. void solve(){
25.
26. ll n; cin>>n;
27. vector<ll>v;
28. ll mini = LONG_LONG_MAX;
29. ll min_idx = -1;
30. for(int i=0; i<n; i++){
31.   ll x; cin>>x;
32.   v.push_back(x);
33.   if(x<mini){
34.     mini =x;
35.     min_idx = i;
36.   }
37. }
38.
39. ll maxi = *max_element(v.begin(),v.begin()+min_idx);
40. for(int i=0; i<min_idx; i++){
41.   if(v[i] == maxi){
42.     swap(v[min_idx],v[i]);
43.     break;
44.   }
45. }
46. ll sum =0;
47. for(int i=0; i<n; i++){
48.   sum += (v[i]*(i+1));
49. }
50. cout<<sum<<nl;
51.
52.
53.
54. }
55.
56. int main(){
57. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
58. freopen("cals.in", "r", stdin);
59. int t =1;
60. cin>>t;
61. while(t--){
62. solve();
63. }
64. return 0;
65. }