https://app.codility.com/c/run/trainingMY49MT-P3G/
// 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;
}
'Codility' 카테고리의 다른 글
[Codility] Caterpillar Method : AbsDistinct (0) | 2021.07.16 |
---|---|
[Codility] Caterpillar method : CountTriangles (0) | 2021.07.16 |
[Codility] Lesson15 - Caterpillar method: MinAbsSumOfTwo (0) | 2021.07.16 |
Codility MaxNonoverlappingSegments C++ (0) | 2021.07.15 |