문제 이해

입력

출력


문제 풀이


  1. 구현

    #include <string>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    string solution(int n, int t, int m, vector<string> timetable) {
        sort(timetable.begin(), timetable.end());
        vector<int> i_table;
        
        for (auto time: timetable) {
            string h = time.substr(0, 2);
            string m = time.substr(3, 2);
            i_table.push_back(stoi(h) * 60 + stoi(m));
        }
        
        int current = 9 * 60; 
        int idx = 0;
        int last;
            
        for (int i=0; i<n; i++) {
            int count = 0;
            
            for (int j=idx; j<i_table.size(); j++) {
                if (i_table[j] <= current) {
                    idx++;
                    count++;
                    if (count==m) break;
                }
            } 
            
            if (i==n-1) {
                if (count == m) {
                    last = i_table[idx-1] -1;
                } else {
                    last = current;
                }
            }
            
            current += t;
        }
        
        int hh = last / 60;
        int mn = last % 60;
    
        string ans = (hh < 10 ? "0" : "") + to_string(hh) + ":";
        ans += (mn < 10 ? "0" : "") + to_string(mn);
        
        return ans;
    }