1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;
void sort(vector<int> &, int &, int &);
string cases(vector<int> &, int &, int &);
void test(vector<int> &v, int &alice, int &bob) {
vector<int> x = {5, 1, 2, 5, 4, 3};
assert(cases(x, alice, bob) == "9 6");
vector<int> y = {3, 4, 8, 4};
assert(cases(y, alice, bob) == "12 4");
vector<int> z = {2, 1, 2};
assert(cases(z, alice, bob) == "3 1");
cout << "Test cases passed" << endl;
}
int main() {
int one = 0; // Init Alice
int two = 0; // Init Bob
int n;
cin >> n;
vector<int> input(n); //Created vector with n as input
for( int* i = &input[0]; i < &input[input.size()]; i++) { //Loop over input aka 'n'
cin >> *i;
}
sort(input, one, two); //Calling sort function
}
void sort(vector<int> &input, int &one, int &two) { //Function to sort, assign values, and print
sort(input.rbegin(), input.rend()); //Sort vector in descending order from first to last element
for(int i = 0; i < input.size(); i++) { //Loop for i is less than vector
if(i % 2 == 0) { //Determines who's turn it is using modulos. == 0 is Alice; else == Bob
one += input[i];
}
else {
two += input[i];
}
}
cout << one << " " << two << endl;
}
|