For each new day, subtract D from all the previous stacks. Then take the sum of all the positive piles remaining including the new pile for the current day. If this sum is >= X then print the number of the day.