/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
高橋君は N 日間の夏休みに向けて、勉強の計画を立てています。
夏休みの i 日目 (1 \le i \le N) に勉強を行うと、学力が A_i 上がります。
高橋君は、夏休みの中から連続する 1 日以上 K 日以下の期間を選んで「集中特訓」を行うことにしました。
集中特訓の開始日を l 日目、終了日を r 日目とするとき、集中特訓によって得られる学力の合計は \sum_{i=l}^r A_i となります。
高橋君は、集中特訓で得られる学力の合計を X 以上にしたいと考えています。
以下の条件をすべて満たす整数の組 (l, r) の個数を求めてください。
- 1 \le l \le r \le N
- r - l + 1 \le K
- \sum_{i=l}^r A_i \ge X
制約
- 1 \le K \le N \le 10^6
- 1 \le X \le 10^{15}
- 1 \le A_i \le 10^9 (1 \le i \le N)
- 入力はすべて整数
入力
入力は以下の形式で与えられる。
N K X A_1 A_2 \dots A_N
出力
条件を満たす整数の組 (l, r) の個数を 1 行に出力せよ。
入力例 1
4 3 6 3 1 4 2
出力例 1
3
入力例 2
5 2 15 3 5 2 7 4
出力例 2
0
入力例 3
10 4 15 3 8 2 6 1 9 4 5 7 2
出力例 3
11
入力例 4
25 8 5000000000 720194821 391029481 849201948 194820194 629104820 950182740 410293847 839201847 501928374 291048291 938471920 648291038 184920384 759302841 829401823 481920384 392018472 892019482 610293847 520194829 739102847 419203847 891028374 293847192 684920183
出力例 4
4
入力例 5
1 1 1 1
出力例 5
1
Score : 366 pts
Problem Statement
Takahashi is making a study plan for his N-day summer vacation.
Studying on the i-th day (1 \le i \le N) of the summer vacation increases his academic ability by A_i.
Takahashi has decided to conduct an "intensive training" during a contiguous period of at least 1 and at most K days from the summer vacation.
If the intensive training starts on day l and ends on day r, the total increase in academic ability gained from the intensive training will be \sum_{i=l}^r A_i.
Takahashi wants the total increase in academic ability gained from the intensive training to be at least X.
Find the number of pairs of integers (l, r) that satisfy all of the following conditions:
- 1 \le l \le r \le N
- r - l + 1 \le K
- \sum_{i=l}^r A_i \ge X
Constraints
- 1 \le K \le N \le 10^6
- 1 \le X \le 10^{15}
- 1 \le A_i \le 10^9 (1 \le i \le N)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K X A_1 A_2 \dots A_N
Output
Print the number of pairs of integers (l, r) that satisfy the conditions in a single line.
Sample Input 1
4 3 6 3 1 4 2
Sample Output 1
3
Sample Input 2
5 2 15 3 5 2 7 4
Sample Output 2
0
Sample Input 3
10 4 15 3 8 2 6 1 9 4 5 7 2
Sample Output 3
11
Sample Input 4
25 8 5000000000 720194821 391029481 849201948 194820194 629104820 950182740 410293847 839201847 501928374 291048291 938471920 648291038 184920384 759302841 829401823 481920384 392018472 892019482 610293847 520194829 739102847 419203847 891028374 293847192 684920183
Sample Output 4
4
Sample Input 5
1 1 1 1
Sample Output 5
1