fork download
  1. #define lli long long int
  2. int Solution::solve(vector<int> &A, vector<int> &B, int C) {
  3. vector<int> arr;
  4. sort(A.begin(), A.end());
  5. int n = (int)A.size();
  6. int m = (int)B.size();
  7. for(int i=0;i<n;i++){
  8. arr.push_back(A[i]);
  9. }
  10. for(int i=0;i<n;i++){
  11. arr.push_back(C + A[i]);
  12. }
  13. int p = 2*n;
  14. int dp[p][p];
  15. for(int i=0;i<p;i++){
  16. for(int j=0;j<p;j++){
  17. dp[i][j] = 1e7;
  18. }
  19. }
  20. int minval = 1e7;
  21. for(int i=0;i<m;i++){
  22. minval = min(minval, B[i]);
  23. }
  24. for(int i=0;i<p;i++){
  25. dp[i][i] = minval;
  26. }
  27. for(int i=1;i<n;i++){
  28. for(int j=0;j<p;j++){
  29. int y = j + i;
  30. if(y < p){
  31. for(int k=0;k<m;k++){
  32. int z = arr[j] + B[k];
  33. int l=j,r=p,mid,ans=-1;
  34. while(l <= r){
  35. mid = (l+r)/2;
  36. if(arr[mid] > z){
  37. ans = mid;
  38. r = mid - 1;
  39. }else{
  40. l = mid + 1;
  41. }
  42. }
  43. if(ans == -1 || ans > y){
  44. dp[j][y] = min(dp[j][y], B[k]);
  45. }else{
  46. dp[j][y] = min(dp[j][y], B[k] + dp[ans][y]);
  47. }
  48. }
  49. }
  50. }
  51. }
  52. int fin_ans = 1e7;
  53. for(int i=0;i<n;i++){
  54. fin_ans = min(fin_ans, dp[i][i+n-1]);
  55. }
  56. return fin_ans;
  57. }
  58.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:5: error: ‘Solution’ has not been declared
 int Solution::solve(vector<int> &A, vector<int> &B, int C) {
     ^~~~~~~~
prog.cpp:2:21: error: ‘vector’ was not declared in this scope
 int Solution::solve(vector<int> &A, vector<int> &B, int C) {
                     ^~~~~~
prog.cpp:2:28: error: expected primary-expression before ‘int’
 int Solution::solve(vector<int> &A, vector<int> &B, int C) {
                            ^~~
prog.cpp:2:37: error: ‘vector’ was not declared in this scope
 int Solution::solve(vector<int> &A, vector<int> &B, int C) {
                                     ^~~~~~
prog.cpp:2:44: error: expected primary-expression before ‘int’
 int Solution::solve(vector<int> &A, vector<int> &B, int C) {
                                            ^~~
prog.cpp:2:53: error: expected primary-expression before ‘int’
 int Solution::solve(vector<int> &A, vector<int> &B, int C) {
                                                     ^~~
prog.cpp:2:58: error: expression list treated as compound expression in initializer [-fpermissive]
 int Solution::solve(vector<int> &A, vector<int> &B, int C) {
                                                          ^
stdout
Standard output is empty