Study Record

[프로그래머스] Level2 - 기능개발 본문

알고리즘

[프로그래머스] Level2 - 기능개발

초코초코초코 2021. 12. 3. 11:31
728x90
#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> progresses, vector<int> speeds) {
    vector<int> answer;
    int day = 0, i=0, len = speeds.size();
    
    while(i < len){
        int needDay = (100 - progresses[i])/speeds[i];
        if( (100 - progresses[i]) % speeds[i] != 0) needDay++;
        int num = 1;
        if(day != needDay && day < needDay) day = needDay;
        i++;
        while(i < len){
            if(progresses[i] + day * speeds[i] >= 100){
                num++;
                i++;
            } else  break;
        }
        answer.push_back(num);
    }
    
    return answer;
}
728x90