Home AtCoder. 016 Minimum Coins(3)
Post
Cancel

AtCoder. 016 Minimum Coins(3)

[Link] https://AtCoder.jp/contests/typical90/tasks/typical90_p


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(), ans = Integer.MAX_VALUE;
    int[] input = new int[] { sc.nextInt(), sc.nextInt(), sc.nextInt() };
    Arrays.sort(input);
    int a = input[2], b = input[1] , c = input[0];

    int max = 9999;
    for(int i = Math.min(max, n/a); i >= 0; i--) {
      for(int j = Math.min(max - i, (n - i * a) / b); j >= 0 ; j--) {
        int left = n - a * i - b * j, quotient = left / c;
        if(left - c * quotient == 0) ans = Math.min(ans, i + j + quotient);
      }
    }
    System.out.println(ans);
  }
}
This post is licensed under CC BY 4.0 by the author.