Skip to content

Commit 14f4080

Browse files
committed
feat: DCC 12-11-2024 added.
1 parent d102083 commit 14f4080

File tree

1 file changed

+36
-0
lines changed
  • solutions/2070. Most Beautiful Item for Each Query

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
public class Solution
2+
{
3+
public int[] MaximumBeauty(int[][] items, int[] queries)
4+
{
5+
int[] ans = new int[queries.Length];
6+
int[] maxBeautySoFar = new int[items.Length + 1];
7+
8+
Array.Sort(items, (a, b) => a[0].CompareTo(b[0]));
9+
10+
for (int i = 0; i < items.Length; ++i)
11+
maxBeautySoFar[i + 1] = Math.Max(maxBeautySoFar[i], items[i][1]);
12+
13+
for (int i = 0; i < queries.Length; ++i)
14+
{
15+
int index = FirstGreater(items, queries[i]);
16+
ans[i] = maxBeautySoFar[index];
17+
}
18+
19+
return ans;
20+
}
21+
22+
private int FirstGreater(int[][] items, int q)
23+
{
24+
int l = 0;
25+
int r = items.Length;
26+
while (l < r)
27+
{
28+
int m = (l + r) / 2;
29+
if (items[m][0] > q)
30+
r = m;
31+
else
32+
l = m + 1;
33+
}
34+
return l;
35+
}
36+
}

0 commit comments

Comments
 (0)