🌞Algorithm/🔥Baekjoon

[Baekjoon] 11999_Milk Pails (Bronze)

뿌야._. 2025. 5. 7. 12:35
문제(출처: https://www.acmicpc.net/problem/11999)

< Milk Pails (Bronze) >

 

문제 풀이 

 

X와 Y를 사용하여 만들 수 있는 M이하 최댓값을 구한다.

 

my solution (Java)

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.StringTokenizer;
 
 public class _11999_ { // Milk Pails (Bronze)
 
 	public static void main(String[] args) throws IOException {
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		StringTokenizer st = new StringTokenizer(bf.readLine());
 
 		int X = Integer.parseInt(st.nextToken());
 		int Y = Integer.parseInt(st.nextToken());
 		int M = Integer.parseInt(st.nextToken());
 
 		int q = M / X;
 
 		int result = X * q--;
 
 		int cnt = 1;
 		while (cnt <= M / Y) {
 			int temp = X * q--;
 			if (temp + (Y * cnt) <= M) {
 				temp += (Y * cnt++);
 			}
 			result = Math.max(result, temp);
 		}
 		System.out.println(result);
 	}
 }
변수)
X, Y, M : 입력값
q : M을 X로 나눈 몫
result : 최댓값
cnt : Y를 사용하는 횟수

 

X, Y, M을 입력받는다. 먼저 X만을 사용하여 만들 수 있는 M이하 최댓값을 구해 result에 저장한다. 그 후 X 사용 개수를 줄여가며 Y를 더해 만들 수 있는 M이하 최댓값을 구한다.

 

최종 result를 출력한다.



 

'🌞Algorithm > 🔥Baekjoon' 카테고리의 다른 글

[Baekjoon] 9626_크로스워드 퍼즐  (0) 2025.05.09
[Baekjoon] 6212_Dream Counting  (1) 2025.05.08
[Baekjoon] 5976_A spiral walk  (1) 2025.05.02
[Baekjoon] 11809_YODA  (1) 2025.05.01
[Baekjoon] 28464_Potato  (1) 2025.04.30