슈콩

[SWEA] 증가하는 사탕 수열 본문

Algorithms/SWEA

[SWEA] 증가하는 사탕 수열

shukong 2025. 11. 16. 19:52

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AY4XhKTKU0IDFARM

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int[] candy = new int[3];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<3;i++) {
				candy[i] = Integer.parseInt(st.nextToken());
			}
			int result = 0;
			for(int i=2;i>=1;i--) {
				if(candy[i]<=candy[i-1]) {
					if(candy[i]-1<=0) {
						result = -1;
						break;
					}
					result += candy[i-1] - candy[i] + 1;
					candy[i-1] = candy[i] - 1;
				}
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 24시간  (0) 2025.11.16
[SWEA] 외로운 문자  (0) 2025.11.16
[SWEA] 통나무 자르기  (0) 2025.11.16
[SWEA] 피보나치 수 분배  (0) 2025.11.16
[SWEA] 지명 선수  (0) 2025.11.16