[22864번] 피로도 ( 그리디 - 1 )

Loopy·2024년 1월 13일
0

코테 문제들

목록 보기
83/113


✅ 코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		st = new StringTokenizer(br.readLine());

		int A = Integer.parseInt(st.nextToken());
		int B = Integer.parseInt(st.nextToken());
		int C = Integer.parseInt(st.nextToken());
		int M = Integer.parseInt(st.nextToken());

		int T = 24;
		int cnt = 0;
		int myA = 0;

		if (A > M) {
			System.out.println(0);
			return;
		}

		while (true) {
			if (T == 0) break;
			if (myA + A <= M) {
				cnt++;
				myA += A;
			} else {
				myA -= C;
				if (myA < 0) myA = 0;
			}
			T--;
		}

		System.out.println(cnt * B);

	}
}

profile
잔망루피의 알쓸코딩

0개의 댓글