Advertisement
tungSfer

Untitled

Dec 19th, 2021
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define el endl
  5. #define ll long long
  6. #define umi unordered_map<int, int>
  7. #define umll unordered_map<ll, ll>
  8. #define all(vect) vect.begin(), vect.end()
  9. #define reset(A) memset(A, 0, sizeof(A))
  10. #define approx(n) fixed << setprecision(n)
  11. #define pb push_back
  12.  
  13. const int mod = 1e9 + 7;
  14.  
  15. void solve() {
  16.     ll n;
  17.     cin >> n;
  18.     ll a[n + 1];
  19.     ll minn = 0;
  20.     for(int i = 0; i < n; i++) {
  21.         cin >> a[i];
  22.         if(a[minn] > a[i]) {
  23.             minn = i;
  24.         }
  25.     }
  26.     ll min2 = 0;
  27.     if(minn == 0) {
  28.         min2 = 1;
  29.     }
  30.     for(int i = 0; i < n; i++) {
  31.         if(i != minn) {
  32.             if(a[min2] > a[i])
  33.                 min2 = i;
  34.         }
  35.     }
  36.  
  37.     ll min3 = 0;
  38.     for(int i = 0; i < n; i++) {
  39.         if(i != minn && i != min2) {
  40.             if(a[min3] > a[i])
  41.                 min3 = i;
  42.         }
  43.     }
  44.     cout << (a[minn] + a[min3] + a[min2]) << el;
  45.  
  46. }
  47.  
  48. int main() {
  49.     int t = 1;
  50.     cin >> t;
  51.     // cin.ignore();
  52.     while(t--) {
  53.         solve();
  54.     }
  55.     return 0;
  56. }
  57. /*
  58.  
  59. 2
  60. 7
  61. 1 2 3 0 -1 8 10
  62. 9 8 20 3 4 -1 0
  63.  
  64. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement