fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e6+14;
  4. int n, arr[maxn];
  5. void solve(){
  6. cin >> n;
  7. int idx = 1, a = - 1e9, b = - 1e9;
  8. for (int i = 1; i <= n; i++) {
  9. cin >> arr[i];
  10. if (arr[i] > a) {
  11. a = arr[i];
  12. idx = i;
  13. }
  14. }
  15. for (int i = 1; i <= n; i++) {
  16. if (i == idx) continue;
  17. b = max(b, arr[i]);
  18. }
  19.  
  20. cout << a + b;
  21. }
  22. int main(){
  23. ios_base::sync_with_stdio(0);
  24. cin.tie(0); cout.tie(0);
  25. if (fopen("input.txt","r")){
  26. freopen("input.txt","r",stdin);
  27. freopen("output.txt","w",stdout);
  28. }
  29. solve();
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
-2000000000