cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

reading_books.cpp (841B)


      1 #include <bits/stdc++.h>
      2 #include <ext/pb_ds/assoc_container.hpp>
      3 #include <ext/pb_ds/tree_policy.hpp>
      4 using namespace std;
      5 using namespace __gnu_pbds;
      6 
      7 template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
      8 
      9 using ui = unsigned int;
     10 using l = long;
     11 using ul = unsigned long;
     12 using ll = long long;
     13 using ull = unsigned long long;
     14 
     15 using vi = vector<int>;
     16 using vui = vector<ui>;
     17 using vl = vector<l>;
     18 using vul = vector<ul>;
     19 using vll = vector<ll>;
     20 using vull = vector<ull>;
     21 
     22 void solve()
     23 {
     24 	int n;
     25 	cin >> n;
     26 	l rst = 0;
     27 	l mx = 0;
     28 	for (int i = 0; i < n; i++) {
     29 		l t;
     30 		cin >> t;
     31 		rst += t;
     32 		mx = max(t, mx);
     33 	}
     34 	rst -= mx;
     35 
     36 	if (mx > rst) {
     37 		cout << 2 * mx << "\n";
     38 	} else {
     39 		cout << mx + rst << "\n";
     40 	}
     41 }
     42 
     43 int main()
     44 {
     45 	ios::sync_with_stdio(0);
     46 	cin.tie(0);
     47 	solve();
     48 }