백준 #2839번 설탕 배달

jhj·2025년 5월 8일

백준 JAVA

목록 보기
577/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int num = sc.nextInt();
		int count5 = 0;
		int count3 = 0;
		int total = 0;
		int i;
		int a = num / 5;
		
		if(num % 5 == 0) {
			System.out.println(num / 5);
		}else {
			for(i = a; i >= 0; i--) {
				count5 = i;
				count3 = (num - count5 * 5) / 3;
				
				if(count5 * 5 + count3 * 3 == num) {
					break;
				}
			}
			
			if(i == -1) {
				System.out.println("-1");
			}else {
				total = count5 + count3;
				System.out.println(total);
			}
		}
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글