やるだけ
class BirthdayReminders { public: vector <string> remind(vector <string> friendNames, vector <int> birthDates, int currentDate, vector <string> occasions, vector <int> days, int k) { vector< vector<int> > v; const int N = friendNames.size(); const int M = occasions.size(); for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { int m = currentDate - birthDates[i]; int n = m / days[j] + (bool)(m % days[j]); for (int loop = 100; loop--; ++n) { int D = birthDates[i] + n * days[j]; vector<int> u; u.push_back(D); u.push_back(j); u.push_back(i); u.push_back(n); v.push_back(u); } } } sort(v.begin(), v.end()); char buff[1000]; vector<string> ret; for (int i = 0; i < k; ++i) { sprintf(buff, "%d. %s %s (%d)", v[i][0], friendNames[v[i][2]].c_str(), occasions[v[i][1]].c_str(), v[i][3]); ret.push_back(string(buff)); } return ret; } };