본문 바로가기

코드포스

[코드포스 Practice9] B. New Year Garland

Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.

Polycarp은 슬퍼요ㅠㅠ 왜냐면 새해가 며칠 이내로 오는데 도시에 눈이 안 내렸기 때문이에요. 그래서 새해 분위기를 내기 위해 그는 집을 몇 개의 garland로 꾸미기로 했다.

 


The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!

동네 가게는 올해 "직접 너만의 garland를 만들어 보세요!"라는 새로운 서비스를 소개했다. 그래서 너는 빨강, 초록, 파랑색 전구를 사서 그것들을 제공해 주면, 가게 직원들이 하나의 garland를 납땜 할 것이다. 결과 garland는 (완성된 garland 는) 너가 제공한 모든 램프를 일렬로 포함할 것이다. 게다가 이 garland에 같은 색의 램프 어느 쌍도 인접하지 않을 것이다.

For example, if you provide 3 red, 3 green and 3 blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.

예를 들어 만약 너가 빨간색 3개 녹색 3개 파란색3개를 제공한다면 완성된 garland는 이렇게 생겼을 수 있다 : "RGBRBGBGR"("RGB"는 각각 빨, 초, 파이다). garland의 끝에는 같은 색깔의 전구가 와도 괜찮다.


However, if you provide, say, 1 red, 10 green and 2 blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.

하지만 만약 너가 빨강 1개 초록 10개 파랑 2개를 제공한다면, 가게 직원들은 이것들로 어떠한 garland도 만들 수 없다. 이 전구들로 구성된 어떤 garland도 적어도 한 쌍의 같은 색으로 인접한 전구쌍을 가질 것이다. 가게 직원들이 너가 제공한 전구 모두를 사용해야 한다는 걸 알아둬라.


So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.

그래서 Polycarp은 몇 개의 전구를 샀고 이제 그는 가게 직원이 이것들로 garland를 만들 수 있는지 알고싶다.

Input
The first line contains a single integer t (1≤t≤100) — the number of sets of lamps Polycarp has bought.

첫 번째 줄은 하나의 정수 t를 포함한다. -- Polycarp이 산 전구의 개수


Each of the next t lines contains three integers r, g and b (1≤r,g,b≤109) — the number of red, green and blue lamps in the set, respectively.

다음 t 줄 각각은 세 개의 정수 r, g, b를 포함한다. -- 각각 빨 초 파 전구의 개수이다.

Output
Print t lines — for each set of lamps print "Yes" if the store workers can build a garland from them and "No" otherwise.

t줄을 출력해아. -- 만약 직원이 이것들로 garland를 만들 수 있으면 "Yes"출력하고 그렇지 않으면 "No"를 출력해라 


인접하지 않게 하는 건 규칙이 있는 듯.. 하나를 기준으로 잡고 인접하지 않는 조건이 되는가?를 물으면 된다. 

서로 연속되지 않게 하려면 사이사이에 다른 색을 넣으면 되니깐 다른 색의 개수가 기준 색 -1한 것보다 많은지 를 확인하면 된다. 아니면 연속이 되어버림

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
 
using namespace std;
using i64 = long long;
 
int main() {
    int q;
    scanf("%d", &q);
    
    for(int i = 0; i < q; i++){
        int r, g, b;
        scanf("%d %d %d", &r, &g, &b);
        
        if(r-1 > g+b)
            printf("No\n");
        else if(g-1 > r+b)
            printf("No\n");
        else if(b-1 > g+r)
            printf("No\n");
        else
            printf("Yes\n");
    }
    
    
    return 0;
}