Created
July 25, 2016 02:49
-
-
Save aadimator/2eacc7a2f5f76635733db641e82a8dfe to your computer and use it in GitHub Desktop.
Minimum Dot Product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
using std::vector; | |
long long min_dot_product(vector<int> a, vector<int> b) { | |
std::sort(a.begin(), a.end()); | |
std::sort(b.begin(), b.end(), std::greater<int>()); | |
long long result = 0; | |
for (int i = 0; i < a.size(); i++) { | |
result += (long long) a[i] * b[i]; | |
} | |
return result; | |
} | |
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 << min_dot_product(a, b) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment