#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
ll min_total_length(vector<int> r, vector<int> b){
int dp[205][205];
int n = r.size();
int m = b.size();
for(int i = 0; i < n+1; i++){
for(int j = 0; j < m+1; j++){
if(i == 0 || j == 0){
dp[i][j] = 0;
}else{
dp[i][j] = INT_MAX;
dp[i][j] = min(min(dp[i-1][j], dp[i-1][j-1]), dp[i][j-1]) + abs(r[i-1] - b[j-1]);
}
}
}
return dp[n][m];
}
// int main(){
// int R[] = {1, 2, 3, 7};
// int B[] = {0, 4, 5, 9, 10};
// cout << min_total_length({1, 2, 3, 7}, {0, 4, 5, 9, 10}) << '\n';
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |