Problem details
https://codeforces.com/contest/1955/problem/A
Problem - A - Codeforces
codeforces.com
Ideas
- If 2a > b, then buy as much as you can at the b price.
If 2a < b, then buy as much as you can at the a price. - If n is odd, then you should buy at least one at the a price.
Answer code (Java)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t, n, a, b, ans;
t = sc.nextInt();
for (int i = 0; i < t; i++) {
ans = 0;
n = sc.nextInt();
a = sc.nextInt();
b = sc.nextInt();
// Idea2 : If n is odd, then you should buy at least one at the a price.
if (n % 2 == 1) {
ans += a;
n--;
}
// Idea1 : If 2a > b, then buy as much as you can at the b price.
// If 2a < b, then buy as much as you can at the a price.
if (2 * a > b) {
ans += n / 2 * b;
} else {
ans += n * a;
}
System.out.println(ans);
}
}
}
'-- 기타 -- > Problem Solve' 카테고리의 다른 글
[Codeforces Round 939] A. Nene's Game (0) | 2024.04.14 |
---|---|
[Codeforces Round 938] B. Progressive Square (0) | 2024.04.14 |
[백준] JAVA11 컴파일 환경 (0) | 2023.11.24 |
[코드업] 1403번: 배열 두번 출력하기 (0) | 2023.11.22 |
[코드업] 1083번 문제 (0) | 2023.11.21 |