알고리즘왕/BOJ

[백준/2839/JAVA] 설탕 배달

찌 ㅋ 2020. 3. 18. 20:33

 

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		System.out.println(solution(x));
	}
	static int solution(int x) {
		int result = -1;
		int s = x/5;
		while(s > 0) {
			if((x-s*5)%3 == 0)
				return s + (x-s*5)/3;
			s--;
		}
		if(x%3 == 0)
			return x/3;
		return result;
	}
}

 


 

'알고리즘왕 > BOJ' 카테고리의 다른 글

[백준/1193/JAVA] 분수찾기  (0) 2020.03.18
[백준/2292/JAVA] 벌집  (0) 2020.03.18
[백준/1712/JAVA] 손익분기점  (0) 2020.03.18
[백준/1316/JAVA] 그룹 단어 체커  (0) 2020.03.18
[백준/5622/JAVA] 다이얼  (0) 2020.03.18