Uiro
시간 제한5초메모리 제한2048 MB
각 질의 구간에서 0부터 시작해 카드를 순서대로 더하거나 빼되 중간값이 음수가 되지 않게 하며 뺄셈 횟수의 최댓값을 구한다.
문제
Aoi has cards numbered from to . Each card has a positive integer written on it. The integer written on the card () is .
Aoi is going to play a game times using the cards and a blackboard. The -th game () she plays consists of the following steps.
-
Write on the blackboard.
-
Arrange the cards on the desk from left to right in this order.
-
Perform the following operation for times. The -th operation () is as follows.
- Let be the current integer written on the blackboard, and let be the integer written on the -th card from the left on the desk. Erase from the blackboard, and write either or instead. If is chosen, Aoi eats one piece of uiro, a traditional Japanese sweet.
- However, writing an integer strictly less than is not allowed.
For each game, you want to know the maximum number of uiro pieces Aoi can eat.
Given the information about cards and games, write a program that, for each game, calculates the maximum number of uiro pieces Aoi can eat.
입력
Read the following data from the standard input.
출력
Write lines to the standard output. In the -th line (), output the maximum number of uiro pieces Aoi can eat in the -th game.
제한
- .
- ().
- .
- ().
- Given values are all integers.