题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1774&rd=5869
解答分析:http://community.topcoder.com/tc?module=Static&d1=match_editorials&d2=srm223
水题,不多解释。
代码如下:
#include <string> #include <vector> using namespace std; class MostProfitable { public: string bestItem(vector <int> costs, vector <int> prices, vector <int> sales, vector <string> items) { string res = ""; long long most = 0LL; for (int i = 0; i < costs.size(); i++) { int prof = ( prices[i] - costs[i] ) * sales[i]; if (prof > most) { most = prof; res = items[i]; } } return res; } };