summaryrefslogtreecommitdiff
path: root/Sources/GraphAlgo.cpp
blob: d04987fcf79e5fa12c9abafd7927fdd196733803 (plain)
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <gtest/gtest.h>

using std::vector;

static long getMaxDotProduct(vector<int> a, vector<int> b) {
	std::sort(a.begin(), a.end());
	std::sort(b.begin(), b.end());
	long result = 0;
	for (int i = 0; i < b.size(); i++) {
		result = (long) a[i]*b[i]+result;
	}
	return result;
}

TEST(MaxDotProduct, Max1) {
	vector<int> a = { 60, 100, 120 };
	vector<int> b = { 20, 50, 30 };
	ASSERT_EQ(getMaxDotProduct(a, b), 10200);
}

//TEST(MaxDotProduct, Max2) {
//	vector<int> a = { 23 };
//	vector<int> b = { 39 };
//	ASSERT_EQ(getMaxDotProduct(a, b), 897);
//}
//
//TEST(MaxDotProduct, Max3) {
//	vector<int> a = { 1,3,-5 };
//	vector<int> b = { -2,4,1 };
//	ASSERT_EQ(getMaxDotProduct(a, b), 23);
//}

//int main() {
//  size_t n;
//  std::cin >> n;
//  vector<int> a(n), b(n);
//  for (size_t i = 0; i < n; i++) {
//    std::cin >> a[i];
//  }
//  for (size_t i = 0; i < n; i++) {
//    std::cin >> b[i];
//  }
//  std::cout << getMaxDotProduct(a, b) << std::endl;
//}