import java.util.*;
import java.math.*;
//rename the class name before submitting
public class MysteriousRestaurant {
public static void main(String[] args) {
MysteriousRestaurant obj = new MysteriousRestaurant();
System.out.println(
obj.maxDays(
new String[]
{}, 0
));
}
public int maxDays(String[] prices, int budget) {
int days = 0;
int[] minps = new int[7];
for (int i = 0; i < 7; i++) {
if (i == prices.length)
break;
int minp = Integer.MAX_VALUE;
for (int j = 0; j < prices[0].length(); j++) {
char c = prices[i].charAt(j);
int price = GetPrice(c);
minp = Math.min(minp, price);
}
minps[i] = minp;
if (budget >= minp) {
budget -= minp;
days++;
}
else
return days;
}
for (int i = 7; i < prices.length; i++) {
int minp = Integer.MAX_VALUE;
for (int j = 0; j < prices[0].length(); j++) {
int price = 0;
for (int k = i % 7; k <= i; k += 7) {
char c1 = prices[k].charAt(j);
price += GetPrice(c1);
}
if (price < minp) {
minp = price;
}
}
if (budget + minps[i % 7] - minp >= 0) {
days++;
budget = budget - minp + minps[i % 7];
minps[i % 7] = minp;
}
else
break;
}
return days;
}
public static int GetPrice(char c) {
int price;
if (c >= '0' && c <= '9')
price = c - '0';
else if (c >= 'A' && c <= 'Z')
price = 10 + c - 'A';
else
price = 36 + c - 'a';
return price;
}
}
No comments:
Post a Comment