TopCoder SRM617: SlimeXSlimonadeTycoon
古いSlimonade
を優先して売るように実装する。
public class SlimeXSlimonadeTycoon { public int sell(int[] morning, int[] customers, int stale_limit) { var n = morning.Length; var stock = new int[n]; int ans = 0; for (int i = 0; i < n; i++) { stock[i] = morning[i]; int c = customers[i]; for (int j = Math.Max(0, i - stale_limit + 1); j <= i; j++) { int use = Math.Min(stock[j], c); c -= use; stock[j] -= use; ans += use; if (c == 0) break; } } return ans; } }