問題一覧 > 通常問題

No.146 Exam Proctoring (1)

レベル : / AI推定難易度 : 214 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 128 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 497
作問者 : LayCurse
お気に入りにしたユーザー ProblemId : 369 / 自分の提出
問題文最終更新日: 2026-06-27 06:03:44
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 84 (順位表) の他の問題:

Problem Statement

A certain teacher (who wishes to remain anonymous) came up with the following problem while proctoring a final exam, with the Setsubun festival going on close by.

To prevent cheating, students may not sit in adjacent seats at the same desk.
For example, at a desk with $3$ chairs, if $2$ students sit there, the only allowed option is to use the chairs at both ends, and if $1$ student sits there, any of the $3$ chairs may be used.
In a certain room, there are $N$ types of desks, and there are $D_k$ desks with $C_k$ chairs.
Here, a desk with $C_k$ chairs has its $C_k$ chairs arranged in a straight line.
Write a program that finds the maximum number of students who can take the exam in this room, modulo ${\rm mod}\ 10^9+7$.


Figure 1. The place where this problem was born (Kyoto University, Room 1-Kyo-01, February 4, 2015)

Input

$N$
$C_1$ $D_1$
$C_2$ $D_2$
$\vdots$
$C_N$ $D_N$

$1 \leq N \leq 100000 = 10^5$
$1 \leq C_k \leq 10^{18}$
$1 \leq D_k \leq 10^{18}$
$C_i \neq C_j$ when $i \neq j$

Output

Output the maximum number of students who can take the exam in this room, modulo ${\rm mod}\ 10^9+7$.

Sample

Sample 1
Input
2
2 5
3 20
Output
45

This is the case of the classroom in the photo.
A desk with 2 chairs can seat at most 1 student and a desk with 3 chairs can seat at most 2 students, so up to 45 students in total can take the exam.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。