알고리즘왕/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;
	}
}