This commit is contained in:
Mrhongxing committed 2026-10-30 14:31:19 +08:00
1 parent de79da4ee7
commit 5ba1fe01aa
3 files changed
+60 -4

No files matched your search

+50 -1
View File
@@ -1,7 +1,56 @@
package com.hong.www;
import java.util.*;
public class A2542 {
public long maxScore(int[] nums1, int[] nums2, int k) {
return 0;
int[][] arr = new int[nums1.length][2];
PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> a - b);
for (int i = 0; i < nums1.length; i++) {
arr[i][0] = nums1[i];
arr[i][1] = nums2[i];
}
Arrays.sort(arr, (a, b) -> b[1] - a[1]);
long sum = 0;
long currentSum = 0;
for (int j = 0; j < nums1.length; j++) {
if (pq.size() < k) {
pq.offer(arr[j][0]);
if (pq.size() == k) {
long temp = 0;
for (int num : pq) {
temp += num;
currentSum += num;
}
sum = temp * arr[j][1];
}
} else {
if (arr[j][0] > pq.peek()) {
currentSum = currentSum - pq.peek() + arr[j][0];
pq.poll();
pq.offer(arr[j][0]);
if (currentSum * arr[j][1] > sum) {
sum = currentSum * arr[j][1];
}
}else {
long temp = 0;
temp= currentSum - pq.peek() + arr[j][0];
if (temp * arr[j][1] > sum) {
sum = temp * arr[j][1];
}
}
}
}
return sum;
}
public static void main(String[] args) {
A2542 a = new A2542();
int[] nums1 = { 2, 1, 14, 12 };
int[] nums2 = { 11, 7, 13, 6 };
int k = 3;
System.out.println(a.maxScore(nums1, nums2, k));
}
}
+7
View File
@@ -0,0 +1,7 @@
package com.hong.www;
public class A69 {
public int Leetcode(String[] words) {
return 0;
}
}
+3 -3
View File
@@ -2,8 +2,8 @@ package com.hong.www;
public class LCP25 {
public int keyboard(int k, int n) {
int[][] dp=new int[k+1][n+1];
for(int i=0;i<=k;i++){
int[][] dp=new int[27][n+1];
for(int i=0;i<=26;i++){
dp[i][0]=0;
}
for(int j=0;j<=n;j++){
@@ -11,7 +11,7 @@ public class LCP25 {
}
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
dp[i][j]=0;
}
}
return dp[k][n];