Skip to content

Commit fcf20d0

Browse files
committed
Runtime: 321 ms (Top 69.62%) | Memory: 89.00 MB (Top 83.54%)
1 parent 40dd192 commit fcf20d0

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
1+
// Runtime: 321 ms (Top 69.62%) | Memory: 89.00 MB (Top 83.54%)
2+
13
class Solution {
24
public:
5+
36
vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {
4-
vector<vector<int>> v;
5-
int n = queries.size();
6-
for(int i = 0; i < n; i++){
7-
v.push_back({queries[i],i});
8-
}
9-
sort(v.begin(),v.end());
107
sort(items.begin(),items.end());
11-
vector<int> ans(n);
12-
int j=0;
13-
n = items.size();
14-
int mx = 0;
15-
for(auto &i: v){
16-
while(j<n && items[j][0]<=i[0]){
17-
mx = max(mx,items[j][1]);
18-
j++;
8+
int maxi = items[0][1];
9+
// for(auto xt : items)
10+
// {
11+
// cout<<xt[0]<<" "<<xt[1]<<endl;
12+
// }
13+
for(auto &xt : items)
14+
{
15+
maxi = max(maxi , xt[1]);
16+
xt[1] = maxi;
17+
}
18+
// for(auto xt : items)
19+
// {
20+
// cout<<xt[0]<<" "<<xt[1]<<endl;
21+
// }
22+
vector<int>ans;
23+
int n = items.size();
24+
25+
for(int key : queries){
26+
int left = 0;
27+
int right = n - 1;
28+
29+
int count = 0;
30+
31+
while (left <= right) {
32+
int mid = (right + left) / 2;
33+
if (items[mid][0] <= key) {
34+
count = mid + 1;
35+
left = mid + 1;
36+
}
37+
else
38+
right = mid - 1;
1939
}
20-
ans[i[1]] = mx;
40+
41+
if(count==0)
42+
ans.push_back(0);
43+
else
44+
ans.push_back(items[count-1][1]);
2145
}
2246
return ans;
2347
}
24-
};
48+
};
49+

0 commit comments

Comments
 (0)