Created
January 9, 2015 12:11
-
-
Save StarOrpheus/f7a601f22ccef9178891 to your computer and use it in GitHub Desktop.
lel
This file contains 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 <iostream> | |
#include <cstdlib> | |
#include <cstdio> | |
#include <iomanip> | |
#include <cmath> | |
#include <string> | |
#include <vector> | |
#include <bitset> | |
#include <deque> | |
#include <memory> | |
#include <algorithm> | |
#include <string.h> | |
using namespace std; | |
int a[10100], b[10010]; | |
int f[1010][1010]; | |
int n, m; | |
int p, q; | |
int i, j; | |
int i1, i2; | |
int main() | |
{ | |
cin >> n >> m >> p >> q; | |
//cout << n << " " << m << endl; | |
memset((void *) a, '?', 1010); | |
memset((void *) b, '?', 1010); | |
memset | |
for(i = 1; i <= n; i++) | |
cin >> a[i]; | |
for(i = 1; i <= m; i++) | |
cin >> b[i]; | |
for(int i = 1; i <= max(n, m); i++) | |
{ | |
i1 = i; | |
i2 = i; | |
for(j = i+1; j <= max(n, m); j++) | |
{ | |
if(a[j] < a[i1]) | |
i1 = j; | |
if(b[j] < b[i2]) | |
i2 = j; | |
} | |
swap(a[i], a[i1]); swap(b[i], b[i2]); | |
} | |
for(i = 0; i <= n; i++) | |
{ | |
f[i][0] = p * i; | |
} | |
for(j = 0; j <= m; j++) | |
f[0][j] = j * q; | |
for(i = 1; i <= n; i++) | |
for(j = 1; j <= m; j++) | |
{ | |
f[i][j] = min(f[i-1][j] + p, f[i][j-1] + q); | |
f[i][j] = min(f[i][j], f[i-1][j-1] + abs(a[i] - b[j])); | |
} | |
cout << f[n][m] << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment