https://app.codility.com/programmers/lessons/15-caterpillar_method/count_triangles/
#include<algorithm>
// 1 2 5 8 10 12
int solution(vector<int> &A) {
sort(A.begin(),A.end());
int sz = A.size();
int answer = 0;
for(int i=0; i<sz-2; i++){
int k = i +2;
for(int j = i+1; j<sz; j++){
while(k <sz && A[i] + A[j] > A[k]){
k+=1;
}
if (k > j)
answer += k - j - 1;
}
}
return answer;
}
'Codility' 카테고리의 다른 글
[Codility] Caterpillar Method : AbsDistinct (0) | 2021.07.16 |
---|---|
[Codility] Lesson15 - Caterpillar method: MinAbsSumOfTwo (0) | 2021.07.16 |
Codility TieRopes C++ (0) | 2021.07.15 |
Codility MaxNonoverlappingSegments C++ (0) | 2021.07.15 |