Created
January 27, 2015 19:26
-
-
Save ik11235/3350988dd57d9254696b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TravellingSalesmanEasy { | |
public: | |
int getMaxProfit(int M, vector<int> profit, vector<int> city, vector<int> visit) { | |
int ans=0; | |
priority_queue<int> qu[M]; | |
for (int i=0; i < profit.size(); i++) { | |
qu[city[i]-1].push(profit[i]); | |
} | |
for (int i=0; i < visit.size(); i++) { | |
if(qu[visit[i]-1].empty()) | |
continue; | |
ans+=qu[visit[i]-1].top(); | |
qu[visit[i]-1].pop(); | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment