Skip to content

Commit

Permalink
Fixed format
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev committed Jan 7, 2025
1 parent c2fddc5 commit 19a5d09
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ private int fun(String s, String k) {
for (j = 0; j < m; j++) {
char ch1 = s.charAt(j + i);
char ch2 = k.charAt(j);
if (ch1 != ch2) break;
if (ch1 != ch2) {
break;
}
}
if (j == m) {
return i + j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@ public class Solution {
public long maximumCoins(int[][] coins, int k) {
Arrays.sort(coins, (a, b) -> a[0] - b[0]);
int n = coins.length;
long res = 0, cur = 0;
long res = 0;
long cur = 0;
for (int i = 0, j = 0; i < n; ++i) {
while (j < n && coins[j][1] <= coins[i][0] + k - 1) {
cur += 1L * (coins[j][1] - coins[j][0] + 1) * coins[j][2];
cur += (long) (coins[j][1] - coins[j][0] + 1) * coins[j][2];
j++;
}
if (j < n) {
long part = 1L * Math.max(0, coins[i][0] + k - 1 - coins[j][0] + 1) * coins[j][2];
long part = (long) Math.max(0, coins[i][0] + k - 1 - coins[j][0] + 1) * coins[j][2];
res = Math.max(res, cur + part);
}
cur -= 1L * (coins[i][1] - coins[i][0] + 1) * coins[i][2];
cur -= (long) (coins[i][1] - coins[i][0] + 1) * coins[i][2];
}
cur = 0;
for (int i = 0, j = 0; i < n; ++i) {
cur += 1L * (coins[i][1] - coins[i][0] + 1) * coins[i][2];
cur += (long) (coins[i][1] - coins[i][0] + 1) * coins[i][2];
while (coins[j][1] < coins[i][1] - k + 1) {
cur -= 1L * (coins[j][1] - coins[j][0] + 1) * coins[j][2];
cur -= (long) (coins[j][1] - coins[j][0] + 1) * coins[j][2];
j++;
}
long part = 1L * Math.max(0, coins[i][1] - k - coins[j][0] + 1) * coins[j][2];
long part = (long) Math.max(0, coins[i][1] - k - coins[j][0] + 1) * coins[j][2];
res = Math.max(res, cur - part);
}
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public int[] maximumWeight(List<List<Integer>> intervals) {
int l = 0, r = i - 1;
while (l <= r) {
int m = (l + r) >>> 1;
if (arr[m][1] < arr[i][0]) l = m + 1;
else r = m - 1;
if (arr[m][1] < arr[i][0]) {
l = m + 1;
} else {
r = m - 1;
}
}
p[i] = r;
}
Expand All @@ -43,9 +46,13 @@ class S {
S[][] dp = new S[n][5];
Comparator<S> cmp =
(a, b) -> {
if (a.sum != b.sum) return a.sum > b.sum ? -1 : 1;
if (a.sum != b.sum) {
return a.sum > b.sum ? -1 : 1;
}
for (int i = 0; i < Math.min(a.x.length, b.x.length); i++) {
if (a.x[i] != b.x[i]) return a.x[i] < b.x[i] ? -1 : 1;
if (a.x[i] != b.x[i]) {
return a.x[i] < b.x[i] ? -1 : 1;
}
}
return Integer.compare(a.x.length, b.x.length);
};
Expand All @@ -68,8 +75,11 @@ class S {
S ans = base;
for (int k = 1; k <= 4; k++) {
S candidate = dp[n - 1][k];
if (ans.sum < candidate.sum) ans = candidate;
else if (ans.sum == candidate.sum && cmp.compare(ans, candidate) > 0) ans = candidate;
if (ans.sum < candidate.sum) {
ans = candidate;
} else if (ans.sum == candidate.sum && cmp.compare(ans, candidate) > 0) {
ans = candidate;
}
}
Arrays.sort(ans.x);
return ans.x;
Expand Down

0 comments on commit 19a5d09

Please sign in to comment.