a31002ea47 2014-01-30 kinaba: #include <iostream> a31002ea47 2014-01-30 kinaba: #include <sstream> a31002ea47 2014-01-30 kinaba: #include <iomanip> a31002ea47 2014-01-30 kinaba: #include <vector> a31002ea47 2014-01-30 kinaba: #include <string> a31002ea47 2014-01-30 kinaba: #include <map> a31002ea47 2014-01-30 kinaba: #include <set> a31002ea47 2014-01-30 kinaba: #include <algorithm> a31002ea47 2014-01-30 kinaba: #include <numeric> a31002ea47 2014-01-30 kinaba: #include <iterator> a31002ea47 2014-01-30 kinaba: #include <functional> a31002ea47 2014-01-30 kinaba: #include <complex> a31002ea47 2014-01-30 kinaba: #include <queue> a31002ea47 2014-01-30 kinaba: #include <stack> a31002ea47 2014-01-30 kinaba: #include <cmath> a31002ea47 2014-01-30 kinaba: #include <cassert> a31002ea47 2014-01-30 kinaba: #include <tuple> a31002ea47 2014-01-30 kinaba: using namespace std; a31002ea47 2014-01-30 kinaba: typedef long long LL; a31002ea47 2014-01-30 kinaba: typedef complex<double> CMP; a31002ea47 2014-01-30 kinaba: a31002ea47 2014-01-30 kinaba: class AlienAndHamburgers { public: a31002ea47 2014-01-30 kinaba: int getNumber(vector <int> type, vector <int> taste) a31002ea47 2014-01-30 kinaba: { a31002ea47 2014-01-30 kinaba: const int N = type.size(); a31002ea47 2014-01-30 kinaba: a31002ea47 2014-01-30 kinaba: vector<pair<int,int>> taste_type; a31002ea47 2014-01-30 kinaba: for(int i=0; i<N; ++i) a31002ea47 2014-01-30 kinaba: taste_type.emplace_back(taste[i], type[i]); a31002ea47 2014-01-30 kinaba: sort(taste_type.rbegin(), taste_type.rend()); a31002ea47 2014-01-30 kinaba: a31002ea47 2014-01-30 kinaba: int best = 0; a31002ea47 2014-01-30 kinaba: a31002ea47 2014-01-30 kinaba: set<int> Y; a31002ea47 2014-01-30 kinaba: int A = 0; a31002ea47 2014-01-30 kinaba: for(auto& tt: taste_type) { a31002ea47 2014-01-30 kinaba: int ta = tt.first; a31002ea47 2014-01-30 kinaba: int ty = tt.second; a31002ea47 2014-01-30 kinaba: if(ta >= 0 || !Y.count(ty)) { a31002ea47 2014-01-30 kinaba: Y.insert(ty); a31002ea47 2014-01-30 kinaba: A += ta; a31002ea47 2014-01-30 kinaba: } a31002ea47 2014-01-30 kinaba: best = max<int>(best, Y.size()*A); a31002ea47 2014-01-30 kinaba: } a31002ea47 2014-01-30 kinaba: a31002ea47 2014-01-30 kinaba: return best; a31002ea47 2014-01-30 kinaba: } a31002ea47 2014-01-30 kinaba: }; a31002ea47 2014-01-30 kinaba: a31002ea47 2014-01-30 kinaba: // BEGIN CUT HERE a31002ea47 2014-01-30 kinaba: #include <ctime> a31002ea47 2014-01-30 kinaba: double start_time; string timer() a31002ea47 2014-01-30 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } a31002ea47 2014-01-30 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) a31002ea47 2014-01-30 kinaba: { os << "{ "; a31002ea47 2014-01-30 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) a31002ea47 2014-01-30 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } a31002ea47 2014-01-30 kinaba: void verify_case(const int& Expected, const int& Received) { a31002ea47 2014-01-30 kinaba: bool ok = (Expected == Received); a31002ea47 2014-01-30 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; a31002ea47 2014-01-30 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } a31002ea47 2014-01-30 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); a31002ea47 2014-01-30 kinaba: #define END verify_case(_, AlienAndHamburgers().getNumber(type, taste));} a31002ea47 2014-01-30 kinaba: int main(){ a31002ea47 2014-01-30 kinaba: a31002ea47 2014-01-30 kinaba: CASE(0) a31002ea47 2014-01-30 kinaba: int type_[] = {1, 2}; a31002ea47 2014-01-30 kinaba: vector <int> type(type_, type_+sizeof(type_)/sizeof(*type_)); a31002ea47 2014-01-30 kinaba: int taste_[] = {4, 7}; a31002ea47 2014-01-30 kinaba: vector <int> taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); a31002ea47 2014-01-30 kinaba: int _ = 22; a31002ea47 2014-01-30 kinaba: END a31002ea47 2014-01-30 kinaba: CASE(1) a31002ea47 2014-01-30 kinaba: int type_[] = {1, 1}; a31002ea47 2014-01-30 kinaba: vector <int> type(type_, type_+sizeof(type_)/sizeof(*type_)); a31002ea47 2014-01-30 kinaba: int taste_[] = {-1, -1}; a31002ea47 2014-01-30 kinaba: vector <int> taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); a31002ea47 2014-01-30 kinaba: int _ = 0; a31002ea47 2014-01-30 kinaba: END a31002ea47 2014-01-30 kinaba: CASE(2) a31002ea47 2014-01-30 kinaba: int type_[] = {1, 2, 3}; a31002ea47 2014-01-30 kinaba: vector <int> type(type_, type_+sizeof(type_)/sizeof(*type_)); a31002ea47 2014-01-30 kinaba: int taste_[] = {7, 4, -1}; a31002ea47 2014-01-30 kinaba: vector <int> taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); a31002ea47 2014-01-30 kinaba: int _ = 30; a31002ea47 2014-01-30 kinaba: END a31002ea47 2014-01-30 kinaba: CASE(3) a31002ea47 2014-01-30 kinaba: int type_[] = {1, 2, 3, 2, 3, 1, 3, 2, 3, 1, 1, 1}; a31002ea47 2014-01-30 kinaba: vector <int> type(type_, type_+sizeof(type_)/sizeof(*type_)); a31002ea47 2014-01-30 kinaba: int taste_[] = {1, 7, -2, 3, -4, -1, 3, 1, 3, -5, -1, 0}; a31002ea47 2014-01-30 kinaba: vector <int> taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); a31002ea47 2014-01-30 kinaba: int _ = 54; a31002ea47 2014-01-30 kinaba: END a31002ea47 2014-01-30 kinaba: CASE(4) a31002ea47 2014-01-30 kinaba: int type_[] = {30, 20, 10}; a31002ea47 2014-01-30 kinaba: vector <int> type(type_, type_+sizeof(type_)/sizeof(*type_)); a31002ea47 2014-01-30 kinaba: int taste_[] = {100000, -100000, 100000}; a31002ea47 2014-01-30 kinaba: vector <int> taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); a31002ea47 2014-01-30 kinaba: int _ = 400000; a31002ea47 2014-01-30 kinaba: END a31002ea47 2014-01-30 kinaba: CASE(5) a31002ea47 2014-01-30 kinaba: int type_[] = {1,2,4,4,3}; a31002ea47 2014-01-30 kinaba: vector <int> type(type_, type_+sizeof(type_)/sizeof(*type_)); a31002ea47 2014-01-30 kinaba: int taste_[] = {100,100,-1,-1,-1}; a31002ea47 2014-01-30 kinaba: vector <int> taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); a31002ea47 2014-01-30 kinaba: int _ = 792; a31002ea47 2014-01-30 kinaba: END a31002ea47 2014-01-30 kinaba: /* a31002ea47 2014-01-30 kinaba: CASE(6) a31002ea47 2014-01-30 kinaba: int type_[] = ; a31002ea47 2014-01-30 kinaba: vector <int> type(type_, type_+sizeof(type_)/sizeof(*type_)); a31002ea47 2014-01-30 kinaba: int taste_[] = ; a31002ea47 2014-01-30 kinaba: vector <int> taste(taste_, taste_+sizeof(taste_)/sizeof(*taste_)); a31002ea47 2014-01-30 kinaba: int _ = ; a31002ea47 2014-01-30 kinaba: END a31002ea47 2014-01-30 kinaba: */ a31002ea47 2014-01-30 kinaba: } a31002ea47 2014-01-30 kinaba: // END CUT HERE