QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 2048 MB Total points: 100

#16823. 红绿灯

Statistics

你正看着一条街上的 $n$ 盏红绿灯。每盏红绿灯都根据两个时间参数 $r$ 和 $g$,在红灯 $r$ 秒和绿灯 $g$ 秒之间交替变换。这两个参数在不同的红绿灯之间可能会有所不同。

你看到所有的红绿灯之前都是绿灯,但刚刚在同一时刻全部变成了红灯。你想知道,需要经过多少秒,所有的红绿灯才会再次全部为绿灯。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10$),表示红绿灯的数量。

接下来的 $n$ 行,每行包含两个整数 $r$ 和 $g$ ($1 \le r, g \le 10$),分别表示一盏红绿灯保持红灯和绿灯的秒数。

输出格式

输出一个整数,表示所有红绿灯再次全部为绿灯的最早时间(秒)。如果这种情况永远不会发生,则输出 $-1$。

样例

样例输入 1

3
2 4
3 1
6 1

样例输出 1

27

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.