#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef unsigned long long uint64; typedef long long int64; using namespace std; bool visited[1000]; bool odd(int x){ return x % 2 == 1; } bool even(int x){ return x % 2 == 0; } bool BFS(vector >& graph, int dest){ queue q; q.push(1); while (!q.empty()){ int front = q.front(); visited[front] = true; if (front == dest){ return true; } q.pop(); for (int i = 0; i < graph[front].size(); ++i){ if (!visited[graph[front][i]]){ q.push(graph[front][i]); } } } return false; } bool comp(const pair& l, const pair& r){ return l.second < r.second; } bool gameOver(const vector >& m, int x, int y){ if (x - 1 >= 0 && y - 1 >= 0){ //top left if (m[x - 1][y] == 1 && m[x][y - 1] == 1 && m[x - 1][y - 1] == 1) return true; } if (x + 1 < m.size() && y - 1 >= 0){ //top right if (m[x][y - 1] == 1 && m[x + 1][y] == 1 && m[x + 1][y - 1] == 1) return true; } if (x - 1 >= 0 && y + 1 < m[0].size()){ //bottom left if (m[x - 1][y] == 1 && m[x][y + 1] == 1 && m[x - 1][y + 1] == 1) return true; } if (x + 1 < m.size() && y + 1 < m[0].size()){ //bottom right if (m[x + 1][y] == 1 && m[x][y + 1] == 1 && m[x + 1][y + 1] == 1) return true; } return false; } int fact(int n){ if (n == 1) return 1; else return n * fact(n - 1); } bool reverseCmp(const int& l, const int& r){ return l > r; } int main(){ int wantCount, toysCount; freopen("toys.in", "r", stdin); scanf("%d %d", &wantCount, &toysCount); int want[5001] = { 0 }; int toys[5001] = { 0 }; for (int i = 0; i < wantCount; ++i){ scanf("%d", &want[i]); } for (int i = 0; i < toysCount; ++i){ scanf("%d", &toys[i]); } sort(&want[0], &want[wantCount], reverseCmp); sort(&toys[0], &toys[toysCount], reverseCmp); int count = 0; for (int i = 0; i < wantCount; ++i){ count += (want[i] * toys[i]); } fclose(stdin); freopen("toys.out", "w", stdout); printf("%d", count); fclose(stdout); return 0; }