読むだけ
class OlympicCandles { public: int numberOfNights(vector <int> C) { int night = 1; while (true) { sort(C.begin(), C.end()); reverse(C.begin(), C.end()); int cnt = 0; for (int i = 0; i < (int)min((int)C.size(), night); ++i) { if (0 < C[i]) ++cnt; --C[i]; } if (cnt == night) ++night; else break; } return night - 1; } };