Advertisement
SaberToaster

Untitled

Oct 4th, 2022
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6.  
  7. int main()
  8. {
  9.     ll n;
  10.     cin >> n;
  11.     ll first, second, max_result = 0, temp;
  12.     cin >> first;
  13.     cin >> second;
  14.     if (first < second)
  15.     {
  16.         swap(first, second);
  17.     }
  18.     for (ll i = 2; i < n; i++)
  19.     {
  20.         cin >> temp;
  21.         if (3 * first + 2 * second - 5 * temp > max_result)
  22.         {
  23.             max_result = 3 * first + 2 * second - 5 * temp;
  24.         }
  25.         if (temp > first)
  26.         {
  27.             first = second;
  28.             second = temp;
  29.         }
  30.         else if (temp > second)
  31.         {
  32.             second = temp;
  33.         }
  34.     }
  35.     cout << max_result;
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement