Editorial for VM7WC '16 #5 Silver - Jayden Eats Chocolate
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
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();
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int arr[] = new int[n+1];
arr[a] = 1; arr[b] = 1; arr[c] = 1;
for (int i = 1; i <= n; i++){
if(arr[i] != 0){
if (i + a <= n){
if (arr[i] + 1 > arr[i+a] || arr[i+a] == 0){
arr[i+a] = arr[i] + 1;
}
}
if (i + b <= n){
if (arr[i] + 1 > arr[i+b] || arr[i+b] == 0){
arr[i+b] = arr[i] + 1;
}
}
if (i + c <= n){
if (arr[i] + 1 > arr[i+c] || arr[i+c] == 0){
arr[i+c] = arr[i] + 1;
}
}
}
}
System.out.println(arr[n]);
}
}
Comments