Skip to content

Instantly share code, notes, and snippets.

@ik11235
Created January 27, 2015 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ik11235/3350988dd57d9254696b to your computer and use it in GitHub Desktop.
Save ik11235/3350988dd57d9254696b to your computer and use it in GitHub Desktop.
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