Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = 1e6 + 10;
- const int INF = 2e9 + 10;
- const int MOD = 1e9 + 7;
- typedef long long ll;
- int main(){
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<ll> v(n);
- for(ll &x : v) {
- cin >> x;
- }
- if(n == 1) {
- cout << v[0] * 2 << endl;
- return 0;
- }
- sort(v.begin(), v.end());
- ll sum = 0;
- for(int i = 0; i < n - 1; ++i) {
- sum += v[i];
- }
- if(sum <= v[n - 1]){
- cout << v[n - 1] * 2 << endl;
- }
- else {
- cout << sum + v[n - 1] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement