2321. 拼接数组的最大分数
class Solution {
public:
int work(vector<int> arr1, vector<int> arr2) {
int s = 0;
int n = arr1.size();
for(auto i: arr1) s+=i;
for(int i = 0; i < n; i++) arr2[i] -= arr1[i];
int dp[n+10];
memset(dp, 0, sizeof dp);
int add = INT_MIN;
for(int i = 1 ;i <= n; i++){
dp[i] = max(dp[i-1] + arr2[i-1], arr2[i-1]);
add = max(add, dp[i]);
}
return s + add;
}
int maximumsSplicedArray(vector<int>& nums1, vector<int>& nums2) {
return max(work(nums1, nums2), work(nums2, nums1));
}
};
网友评论