SRM447 Div.2 Easy
このごろMediumやって散々なのでEasyに里帰り。
やっぱこれは出来るんだよなぁ・・・
方針
与えられた仕事を限界値のある与えられたコンピューターで最大いくつまで処理できるか?という問題で、一つのパソコンは一個の仕事しかできないので降順ソートででかい仕事から片付けられるか探索かけます。
コード
そのまんま
class ImportantTasks { public: int maximalCost(vector <int> complexity, vector <int> computers) { sort(complexity.begin(), complexity.end()); sort(computers.begin(), computers.end()); reverse(complexity.begin(), complexity.end()); reverse(computers.begin(), computers.end()); int c=0,ans=0; for (int i=0; i<computers.size(); i++) { for (int j=c; j<complexity.size(); j++) { if (computers[i]>=complexity[j]) { ans++; c++; break; } c++; } } return ans; } };
降順ソートSTLにありそうですが今んところはsort->reverseで代用。