본문 바로가기
Codility

Codility TieRopes C++

by paysmile 2021. 7. 15.

https://app.codility.com/c/run/trainingMY49MT-P3G/

 

Codility

Your browser is not supported You should use a supported browser. Read more

app.codility.com

 

// you can use includes, for example:
// #include <algorithm>

// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;

int solution(int K, vector<int> &A) {
    int answer = 0;
    int count = 0;

    for(int i=0; i<A.size(); i++){
        if(A[i] >= K){
            answer +=1;
            count = 0;
        }
        else{
            count += A[i];
            if(count >=K) {
            answer +=1;
            count = 0;
            }
        }
    }

    return answer;
}