43 lines
751 B
C++
43 lines
751 B
C++
#include <vector>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
class Solution
|
|
{
|
|
public:
|
|
int sum(vector<int> &A)
|
|
{
|
|
int sum = 0;
|
|
for (int i = 0; i < A.size(); i++)
|
|
sum += A[i];
|
|
return sum;
|
|
}
|
|
|
|
vector<int> fairCandySwap(vector<int> &A, vector<int> &B)
|
|
{
|
|
int diff = (sum(A) - sum(B))/2;
|
|
cout<<diff<<endl;
|
|
for (int i = 0; i < A.size(); i++)
|
|
for (int j = 0; j < B.size(); j++)
|
|
if ((A[i] - B[j]) == diff)
|
|
return vector<int>{A[i], B[j]};
|
|
return vector<int>{0, 0};
|
|
}
|
|
};
|
|
|
|
void outputVector(vector<int> A)
|
|
{
|
|
for (int i = 0; i < A.size(); i++)
|
|
cout<<A[i]<<" ";
|
|
cout<<endl;
|
|
}
|
|
|
|
int main() {
|
|
vector<int> A = {2};
|
|
vector<int> B = {1, 3};
|
|
Solution solution = Solution();
|
|
outputVector(solution.fairCandySwap(A, B));
|
|
return 0;
|
|
}
|