Skip to content

Commit

Permalink
Create 826.maxProfitAssignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-2309 authored Oct 2, 2023
1 parent 6f193fd commit fd7781a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Add Code Here/C++ Leetcode Solutions/826.maxProfitAssignment
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution {
public:
int maxProfitAssignment(vector<int>& d, vector<int>& p, vector<int>& w) {
int n=d.size(),m=w.size(),mini=*min_element(w.begin(),w.end()),maxi=*max_element(w.begin(),w.end());
int ans=0;
vector<pair<int,int>> work;
for(int i=0;i<n;i++){
if( d[i]<=maxi){
work.push_back({d[i],p[i]});
}
}

if(!work.size()) return 0;
// for(auto v:work){
// cout<<v.first<<" "<<v.second<<endl;
// }
for(auto v:w){
int ma=0;
for(auto l:work){
if(l.first<=v){
if(l.second>ma){
ma=l.second;
}
}
}
ans+=ma;
}
return ans;
}
};

0 comments on commit fd7781a

Please sign in to comment.