슈콩

[BOJ] 백준 2839 설탕 배달 본문

Algorithms/Baekjoon

[BOJ] 백준 2839 설탕 배달

shukong 2025. 9. 12. 21:53

[문제]

https://www.acmicpc.net/problem/2839

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int result = Integer.MAX_VALUE;
		for(int i=0;3*i<=n;i++) {
			for(int j=0;5*j<=n;j++) {
				if(i*3 + 5*j == n) {
					result = Math.min(i+j, result);
				}
			}
		}
		if(result==Integer.MAX_VALUE) {
			System.out.println(-1);
			return;
		}
		System.out.println(result);
	}
}