Advertisement
ismaeil

Algo1gr

Aug 12th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define OO INT_MAX
  4.  
  5. vector< int > ClassA ,ClassB;
  6. const int N = 1e2 + 2e1;
  7. int n ,arr[N];
  8.  
  9. int main() {
  10.     cin >> n;
  11.     for(int i = 0 ; i < n ; i++)
  12.         cin >> arr[i];
  13.  
  14.     sort(arr , arr + n);
  15.  
  16.     int SumA = 0 ,SumB = 0;
  17.     for(int i = 0 ; i < n ; i++){
  18.         if( SumA < SumB ) {
  19.             SumA += arr[i];
  20.             ClassA.push_back( arr[i] );
  21.         } else {
  22.             SumB += arr[i];
  23.             ClassB.push_back( arr[i] );
  24.         }
  25.     }
  26.  
  27.  
  28.  
  29.     cout << "First Class: " << SumA << endl;
  30.     for(auto i : ClassA )  cout << i << ' ';
  31.  
  32.     cout << endl;
  33.  
  34.     cout << "Second Class: " << SumA << endl;
  35.     for(auto i : ClassA )  cout << i << ' ' ;
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement