Advertisement
informaticage

Easy 3 solution

Jan 17th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main ( void )
  8. {
  9.  
  10.     freopen ("input.txt","r", stdin );
  11.     freopen ("output.txt","w",stdout);
  12.  
  13.     vector <int> pari;
  14.     vector <int> dispari;
  15.  
  16.     int amount;
  17.  
  18.     cin >> amount;
  19.     int input;
  20.     for ( int i = 0; i < amount; i++ ) {
  21.         cin >> input;
  22.         if ( input % 2 == 0 )
  23.             pari.push_back ( input );
  24.         else
  25.             dispari.push_back ( input );
  26.     }
  27.  
  28.     sort ( pari.begin(), pari.end() );
  29.     sort ( dispari.begin(), dispari.end() );
  30.  
  31.     int pariMax = -1;
  32.     if ( pari.size() >= 2 )
  33.         pariMax = pari[ pari.size() - 1 ] + pari [ pari.size() - 2 ];
  34.  
  35.     int dispariMax = -1;
  36.     if ( dispari.size() >= 2 )
  37.        dispariMax = dispari[ dispari.size() - 1  ] + dispari[ dispari.size() - 2 ];
  38.  
  39.  
  40.     cout << max ( pariMax, dispariMax );
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement