This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
// Macros
#define int long long
#define double long long double
#define pb push_back
#define str string
#define vi vector<int>
#define mp make_pair
#define mi map<int, int>
#define umi unordered_map<int, int>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define all(a) a.begin(), a.end()
#define endl "\n"
int mod = 1000000007;
// int mod = 3;
template<typename T>
void printMap(T a){
cout << "{ ";
for (auto x: a){
cout << x.first << ": " << x.second << " ";
}
cout << "}" << endl;
}
int twopower(int x){
int ans = 0;
if (x == 0) return 0;
while (x%2 == 0){
ans++;
x /= 2;
}
return ans;
}
template<typename T>
void printVector(T a){
for (auto x: a){
cout << x << " ";
}
cout << endl;
}
int max_element(vi a){
int m = -1e17;
for (auto x: a){
m = max(m, x);
}
return m;
}
int max(int x, int y){
if (x > y) return x;
else return y;
}
int sum(vector<int> a){
int ans = 0;
for (auto x: a) ans += x;
return ans;
}
int min(int x, int y){
if (x < y) return x;
else return y;
}
bool comp(int n1, int d1, int n2, int d2){ // returns true if fraction1 is smaller than fraction2
return (n1*d2 < n2*d1);
}
bool equal(int n1, int d1, int n2, int d2){ // returns true if fraction1 is smaller than fraction2
return (n1*d2 == n2*d1);
}
void solve(){
// cout << "i";
int n; cin >> n;
vector<int> a(n);
FOR(i,0,n) cin >> a[i];
sort(all(a));
// cout << "i";
int ans = 0;
if (n == 1){
cout << 0 << endl;
return;
}
FOR(i,0,n-2){
ans += a[i]+a[0];
}
FOR(i,n-2,n){
ans += a[i];
}
cout << ans << endl;
}
int32_t main(){
ios::sync_with_stdio(false);cin.tie(0);
// freopen("factory.in", "r", stdin);
// freopen("factory.out", "w", stdout);
int t = 1;
// cout << "a";
// int t; cin >> t;
while (t--){
// cout << "a";
// str inp; cin >> inp;
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |