CF1194F.Crossword Expert

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only TT seconds after coming.

Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains nn Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number tit_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds).

Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either tit_i seconds or ti+1t_i + 1 seconds to solve the ii-th crossword, equiprobably (with probability 12\frac{1}{2} he solves the crossword in exactly tit_i seconds, and with probability 12\frac{1}{2} he has to spend an additional second to finish the crossword). All these events are independent.

After TT seconds pass (or after solving the last crossword, if he manages to do it in less than TT seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate EE — the expected number of crosswords he will be able to solve completely. Can you calculate it?

Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values — in this problem it means that the expected value of the number of solved crosswords can be calculated as E=∑i=0nipiE = \sum \limits_{i = 0}^{n} i p_i, where pip_i is the probability that Adilbek will solve exactly ii crosswords.

We can represent EE as rational fraction PQ\frac{P}{Q} with Q>0Q \gt 0. To give the answer, you should print P⋅Q−1 mod (109+7)P \cdot Q^{-1} \bmod (10^9 + 7).

今天,阿迪尔别克正在参加概率论考试。不幸的是,当他抵达大学时,已经排起了长长的队伍,许多学生都希望参加同一场考试。阿迪尔别克估计,自己只有在抵达大学 TT 秒后才能开始考试。

幸运的是,阿迪尔别克无需复习那些枯燥的定理或公式,也能打发时间。他的智能手机上有一款应用,其中包含 nn 道日式填字谜题供他求解。阿迪尔别克决定按应用中所列顺序依次求解全部谜题,且不跳过任何一道。对于第 ii 道谜题,给定一个数值 tit_i,表示一名普通填字谜题专家解出该题所需的时间(单位:秒)。

阿迪尔别克是一位真正的填字谜题专家,但遗憾的是,他有时在选择解题路径时运气不佳。因此,他解出第 ii 道谜题所需的时间为 tit_i 秒或 ti+1t_i + 1 秒,二者等概率发生(即以概率 12\frac{1}{2} 恰好用 tit_i 秒解出该题;以概率 12\frac{1}{2} 需额外花费 1 秒才能完成该题)。所有这些事件相互独立。

在经过 TT 秒后(或在他用少于 TT 秒解完最后一道谜题时),阿迪尔别克将关闭该应用(若他在第 TT 秒整恰好完成某道谜题,则该谜题视为已解出;否则,他将完全无法完成当前正在求解的谜题)。他认为,计算 EE —— 即他能完整解出的谜题数量的期望值 —— 将是一个有趣的概率论问题。你能算出它吗?

回忆一下,离散型随机变量的期望值是其所有可能取值按对应概率加权后的平均值;本题中,即解出谜题数量的期望值可计算为 E=∑i=0nipiE = \sum \limits_{i = 0}^{n} i p_i,其中 pip_i 表示阿迪尔别克恰好解出 ii 道谜题的概率。

我们可以将 EE 表示为最简有理分式 PQ\frac{P}{Q},其中 Q>0Q > 0。作为答案,请输出 P⋅Q−1 mod (109+7)P \cdot Q^{-1} \bmod (10^9 + 7)。

输入格式

The first line contains two integers nn and TT (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤T≤2⋅10141 \le T \le 2 \cdot 10^{14}) — the number of crosswords and the time Adilbek has to spend, respectively.

The second line contains nn integers t1,t2,…,tnt_1, t_2, \dots, t_n (1≤ti≤1091 \le t_i \le 10^9), where tit_i is the time it takes a crossword expert to solve the ii-th crossword.

Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them.

第一行包含两个整数 nn 和 TT(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤T≤2⋅10141 \le T \le 2 \cdot 10^{14}),分别表示填字游戏的数量以及 Adilbek 可用的总时间。

第二行包含 nn 个整数 t1,t2,…,tnt_1, t_2, \dots, t_n(1≤ti≤1091 \le t_i \le 10^9),其中 tit_i 表示填字游戏专家解决第 ii 个填字游戏所需的时间。

注意:Adilbek 按照输入中给出的顺序依次解决填字游戏,且不会跳过其中任何一个。

输出格式

Print one integer — the expected value of the number of crosswords Adilbek solves in TT seconds, expressed in the form of P⋅Q−1 mod (109+7)P \cdot Q^{-1} \bmod (10^9 + 7).

输出一个整数——Adilbek 在 TT 秒内解出的填字游戏数量的期望值,以 P⋅Q−1 mod (109+7)P \cdot Q^{-1} \bmod (10^9 + 7) 的形式表示。

输入输出样例

  • 输入#1

    3 5
    2 2 2

    输出#1

    750000007
  • 输入#2

    3 5
    2 1 2

    输出#2

    125000003

说明/提示

The answer for the first sample is equal to 148\frac{14}{8}.

The answer for the second sample is equal to 178\frac{17}{8}.

第一个样例的答案等于 148\frac{14}{8}。

第二个样例的答案等于 178\frac{17}{8}。

输入解题思路,AI测评打分。不知道怎么写?

首页