From 5ba1fe01aaa255c0260472413f733bc06d44dd56 Mon Sep 17 00:00:00 2001 From: Mrhongxing <154480715+Mrhongxing@users.noreply.github.com> Date: Fri, 30 Oct 2026 14:31:19 +0800 Subject: [PATCH] 1.9 --- src/com/hong/www/A2542.java | 51 ++++++++++++++++++++++++++++++++++++- src/com/hong/www/A69.java | 7 +++++ src/com/hong/www/LCP25.java | 8 +++--- 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/com/hong/www/A69.java diff --git a/src/com/hong/www/A2542.java b/src/com/hong/www/A2542.java index b6e9949..412de00 100644 --- a/src/com/hong/www/A2542.java +++ b/src/com/hong/www/A2542.java @@ -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 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)); } } diff --git a/src/com/hong/www/A69.java b/src/com/hong/www/A69.java new file mode 100644 index 0000000..8311d61 --- /dev/null +++ b/src/com/hong/www/A69.java @@ -0,0 +1,7 @@ +package com.hong.www; + +public class A69 { + public int Leetcode(String[] words) { + return 0; + } +} diff --git a/src/com/hong/www/LCP25.java b/src/com/hong/www/LCP25.java index 2270812..22c24ed 100644 --- a/src/com/hong/www/LCP25.java +++ b/src/com/hong/www/LCP25.java @@ -2,16 +2,16 @@ 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++){ dp[0][j]=0; - } + } for(int i=1;i<=k;i++){ for(int j=1;j<=n;j++){ - + dp[i][j]=0; } } return dp[k][n];