Easy Segment Tree Solution :)
Code\n\nclass SegmentTree{\n    vector<int>tree;\n    public:\n    vector<int>nodes;\n    SegmentTree(vector<int>v){\n        int n = v.size();\n        nodes =
# Code\n```\nclass SegmentTree{\n    vector<int>tree;\n    public:\n    vector<int>nodes;\n    SegmentTree(vector<int>v){\n        int n = v.size();\n        nodes = v;\n        tree.resize(4*n);\n        build(1,0,n-1);\n    }\n    int build(int node,int l,int r){\n        if(l==r){\n            tree[node] = l;\n            return l;\n        }\n        int mid = l+(r-l)/2;\n        int left = build(2*node,l,mid);\n        int right = build(2*node+1,mid+1,r);\n        return tree[node] = nodes[left]>nodes[right]?left:right;\n    }\n    int query(int node,int l,int r,int ql,int qr){\n        if(ql==l&&qr==r){\n            return tree[node];\n        }\n        if(ql>r||qr<l){\n            return -1;\n        }\n        int mid = l+(r-l)/2;\n        int left = query(2*node,l,mid,ql,min(mid,qr));\n        int right = query(2*node+1,mid+1,r,max(ql,mid+1),qr);\n        if(left==-1)return right;\n        if(right==-1)return left;\n        return nodes[left]>nodes[right]?left:right;\n    }\n    int update(int node,int l,int r,int tr){  \n        if(l==tr&&r==tr){\n            nodes[tr] = -1;\n            return l;\n        }\n        if(tr>r||tr<l)return tree[node];\n        int mid  = l+(r-l)/2;\n        int left = update(2*node,l,mid,tr);\n        int right = update(2*node+1,mid+1,r,tr); \n        if(left==-1)tree[node] = right;\n        if(right==-1)tree[node] = left;\n        return tree[node] = nodes[left]>nodes[right]?left:right;\n    }\n};\nclass Solution {\npublic:\n    int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n        vector<pair<int,int>>vp;\n        int n = profits.size();\n        for(int i=0;i<n;i++){\n            vp.push_back({capital[i],profits[i]});\n        }\n        sort(vp.begin(),vp.end());\n        for(int i=0;i<n;i++){\n            profits[i] = vp[i].second;\n            capital[i] = vp[i].first;\n        }\n        SegmentTree* sg = new SegmentTree(profits);\n        if(k>n)k = n;\n        while(k){\n            auto it= upper_bound(capital.begin(),capital.end(),w);\n            if(it==capital.begin())return w;\n            it--;\n            int ind = it-capital.begin();\n            int pro = sg->query(1,0,n-1,0,ind);\n            if(sg->nodes[pro]==-1)return w;\n            w+=profits[pro];\n            sg->update(1,0,n-1,pro);\n            k--;\n        }\n        return w;\n    }\n};\n```
['Segment Tree', 'C++']