作為一個馬場的主人,你要安排你的n匹賽馬和另一個馬場的n匹馬比賽。你已經知道了對方馬場的出戰(zhàn)表,即參加每一場的馬的強壯程度。當然你也知道你自己的所有馬的強壯程度。我們假定比賽的結果直接由馬的強壯程度決定,即更壯的馬獲勝(若相同則雙方均不算獲勝),請你設計一個策略,使你能獲得盡量多的場次的勝利。
給定對方每場比賽的馬的強壯程度oppo及你的所有馬的強壯程度horses(強壯程度為整數,且數字越大越強壯)同時給定n,請返回最多能獲勝的場次。
測試樣例:
輸入:[1,2,3],[1,2,3],3
返回:2
class HorseRace {
public:
int winMost(vector<int> oppo, vector<int> horses, int n) {
// write code here
sort(oppo.begin(), oppo.end());
sort(horses.begin(), horses.end());
int res = 0;
for(int i=n-1; i>=0; --i){
if(oppo.back() < horses.back()){
oppo.pop_back();
horses.pop_back();
++res;
}else{
oppo.pop_back();
}
}
return res;
}
};