Skip to content

Improved tasks 3218, 3219, 3220 #1791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// #Medium #Array #Dynamic_Programming #Sorting #Greedy
// #2024_07_18_Time_0_ms_(100.00%)_Space_42.4_MB_(32.85%)

@SuppressWarnings("java:S1172")
public class Solution {
public int minimumCost(int ignoredM, int ignoredN, int[] horizontalCut, int[] verticalCut) {
public int minimumCost(int m, int n, int[] horizontalCut, int[] verticalCut) {
int sum = 0;
for (int hc : horizontalCut) {
sum += hc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@

// #Hard #Array #Sorting #Greedy #2024_07_18_Time_3_ms_(100.00%)_Space_62.6_MB_(25.82%)

@SuppressWarnings("java:S1172")
public class Solution {
private static final int N = 1001;
private static final int[] HORIZONTAL_COUNTS = new int[N];
private static final int[] VERTICAL_COUNTS = new int[N];

public long minimumCost(int m, int n, int[] horizontalCut, int[] verticalCut) {
int[] horizontalCounts = new int[N];
int[] verticalCounts = new int[N];
int max = 0;
for (int x : horizontalCut) {
if (x > max) {
max = x;
}
HORIZONTAL_COUNTS[x]++;
horizontalCounts[x]++;
}
for (int x : verticalCut) {
if (x > max) {
max = x;
}
VERTICAL_COUNTS[x]++;
verticalCounts[x]++;
}
long ans = 0;
int horizontalCount = 1;
int verticalCount = 1;
for (int x = max; x > 0; x--) {
ans += (long) HORIZONTAL_COUNTS[x] * x * horizontalCount;
verticalCount += HORIZONTAL_COUNTS[x];
HORIZONTAL_COUNTS[x] = 0;
ans += (long) VERTICAL_COUNTS[x] * x * verticalCount;
horizontalCount += VERTICAL_COUNTS[x];
VERTICAL_COUNTS[x] = 0;
ans += (long) horizontalCounts[x] * x * horizontalCount;
verticalCount += horizontalCounts[x];
horizontalCounts[x] = 0;
ans += (long) verticalCounts[x] * x * verticalCount;
horizontalCount += verticalCounts[x];
verticalCounts[x] = 0;
}
return ans;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
select transaction_date,
sum(case when amount%2<>0 then amount else 0 end) as odd_sum,
sum(case when amount%2=0 then amount else 0 end) as even_sum from transactions
group by transaction_date order by transaction_date;
group by transaction_date order by transaction_date asc;
Loading