#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e6 + 5;
const int oo = 1e18, mod = 1e9 + 7;
int n, m, k, d[N];
string s;
vector<int> arr;
void process() {
cin >> n;
foru(i,1,n) cin >> d[i];
int minx=oo, idx=1;
foru(i,1,n) {
if (d[i]<minx) {
minx=d[i];
idx=i;
}
}
int res=0;
ford(i,idx-1,1) {
res+=d[i]+minx;
}
foru(i, idx+1, n) {
res+=d[i]+minx;
}
cout << res;
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
8 ms |
2648 KB |
Output is correct |
4 |
Correct |
7 ms |
3420 KB |
Output is correct |
5 |
Correct |
8 ms |
3680 KB |
Output is correct |
6 |
Correct |
7 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
8 ms |
2648 KB |
Output is correct |
4 |
Correct |
7 ms |
3420 KB |
Output is correct |
5 |
Correct |
8 ms |
3680 KB |
Output is correct |
6 |
Correct |
7 ms |
3420 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
2888 KB |
Output is correct |
22 |
Correct |
8 ms |
3676 KB |
Output is correct |
23 |
Correct |
9 ms |
3676 KB |
Output is correct |
24 |
Correct |
8 ms |
3676 KB |
Output is correct |
25 |
Correct |
8 ms |
3420 KB |
Output is correct |
26 |
Correct |
8 ms |
3420 KB |
Output is correct |
27 |
Correct |
10 ms |
3632 KB |
Output is correct |
28 |
Correct |
7 ms |
3420 KB |
Output is correct |
29 |
Correct |
8 ms |
3420 KB |
Output is correct |
30 |
Correct |
8 ms |
3676 KB |
Output is correct |