Art Installation

면접 대비

시간 제한1초메모리 제한2048 MB

요약
필요한 빨강, 초록, 파랑 LED 개수와 보유한 개수, 빨강이나 초록으로 쓸 수 있는 LED와 초록이나 파랑으로 쓸 수 있는 LED의 재고가 주어질 때, 설치를 끝내기 위해 사야 하는 특수 LED의 최소 개수를 구하거나 불가능하면 -1을 출력한다.
난이도

보통10점 중 5점

유형
그리디, 수학, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

Jolie is setting up an art installation for her cat, Millie. The art installation will be made up of multiple LEDs.

Jolie has decided that she needs a specific number of red LEDs, green LEDs, and blue LEDs. After rummaging through her desk, she has found some of each. She can buy two special types of LEDs, one which can be either red or green, and another which can be either green or blue.

How many of the special LEDs will Jolie need to buy to finish her installation?

입력

The first line of input contains three integers rr, gg and bb (0≤r,g,b≤1,0000 \le r,g,b \le 1\\, 000), which are the numbers of red LEDs, green LEDs, and blue LEDs Jolie needs.

The second line contains three integers c_rc\_r, c_gc\_g and c_bc\_b (0≤c_r,c_g,c_b≤1,0000 \le c\_r,c\_g,c\_b \le 1\\, 000), which are the numbers of red LEDs, green LEDs, and blue LEDs Jolie already owns.

The third line contains two integers c_rgc\_{rg} and c_gbc\_{gb} (0≤c_rg,c_gb≤2,0000 \le c\_{rg},c\_{gb} \le 2\\, 000), which are the numbers of special LEDs that can be either red or green, and the number of special LEDs that can be either green or blue, that are available for Jolie to buy.

출력

Output a single integer, which is the total number of LEDs Jolie needs to buy to make her installation. Output −1-1 if there aren’t enough LEDs for her to complete her installation.

예제1

  1. 예제 1

    입력
    583 290 710
    396 65 796
    309 800
    
    예상 출력
    412