No.2142 Segment Zero
タグ : / 解いたユーザー数 133
作問者 :
milkcoffee
/ テスター :
nok0
👑 Problem Statement
There is an integer sequence $A$ of length $N$. Initially, $A_i=i$, that is, $A=(1,2,...,N)$. You can perform the following operation.
- Choose integers $l,r \ (1 \leq l \leq r \leq N)$ and replace each of the values $A_l, A_{l+1}, \cdots , A_r$ with $0$.
Find the minimum number of operations required to make the sum of the elements of $A$ equal to $K$.
Input
$N$ $K$
- $1 \leq N \leq 10^6$
- $0 \leq K < \frac{N(N+1)}{2}$
- All inputs are integers.
Output
Output, as an integer, the minimum number of operations required to make the sum of the elements of $A$ equal to $K$.
Sample
Sample 1
Input
5 7
Output
2
Initially, $A=(1,2,3,4,5)$.
First, performing the operation with $l=1,r=2$ gives $A=(0,0,3,4,5)$.
Next, performing the operation with $l=5,r=5$ gives $A=(0,0,3,4,0)$.
With $2$ operations, the sum of the elements of $A$ has been made equal to $7$.
Sample 2
Input
1000000 1000001
Output
1
It suffices to perform the operation with $l=2,r=999999$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。