RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00082

Svada

Platinum V 플래티넘 V
난이도
1s
시간 제한
32MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

The local zoo has acquired a large open garden in which animals may freely move as in their natural habitats and entertain visitors with their usual shenanigans.

The most popular animals are monkeys. With their climbing and jumping and other skills, they delight old and young visitors alike.

One species of monkey has specialized in climbing tall trees and picking off coconuts. Another species has specialized in breaking them open.

There are \(N\) monkeys of the first type (numbered \(1\) through \(N\)) and \(M\) monkeys of the second type (numbered \(1\) through \(M\)).

Monkey \(k\) of the first type takes \(A_k\) seconds to find a good spot on the tree, after which it picks off its first coconut. After that the monkey produces a new coconut every \(B_k\) seconds.

Monkey \(k\) of the second type takes \(C_k\) seconds to find a good tool for opening the coconuts, after which it opens its first coconut. After that the monkey opens another coconut every \(D_k\) seconds.

Unfortunately, the second type of monkey is extremely aggressive so the two types may not be in the garden at the same time. Therefore, zoo keepers will chase away the first type of monkeys as soon as they have picked off all the coconuts. Similarly, if monkeys of the second type stay too long after opening all the coconuts, fights will ensue, so zoo keepers will send them away as soon as they have opened all the coconuts.

The zoo keepers first arrive immediately after all coconuts have been picked, and again immediately after the monkeys open them all. The time needed for monkeys to enter or leave the garden is also negligibly small.

Tomislav especially likes the second type of monkey, but can never guess when to arrive in order to see them. Help him calculate the time when the second type arrives if he knows the total time that monkeys spent in the garden, but does not know the number of coconuts in the garden.

제약
입력 형식

The first line contains the integer \(T\) (\(1 \le T \le 10^9\)), the total time that monkeys spent in the garden, in seconds.

The next line contains the integer \(N\) (\(1 \le N \le 100\)), the number of monkeys of the first type.

Each of the following \(N\) lines contains two integers \(A_k\) and \(B_k\) (\(1 \le A_k, B_k \le 10^9\)), how fast monkey \(k\) of the first type is.

The next line contains the integer \(M\) (\(1 \le M \le 100\)), the number of monkeys of the second type.

Each of the following \(M\) lines contains two integers \(C_k\) and \(D_k\) (\(1 \le C_k, D_k \le 10^9\)), how fast monkey \(k\) of the second type is.

출력 형식

Output the number of seconds between the arrival of the first type of monkeys and the arrival of the
second type.
Contest #2, \(15^{th}\) November 2008

서브태스크
서브태스크점수설명

Subtask 1

100점
예제 1
입력
12
1
3 1
1
5 1
출력
5
예제 2
입력
20
2
3 2
1 3
3
3 1
4 1
5 1
출력
13
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 2

평가 및 의견

Svada

개요
출제자 난이도 Platinum V 플래티넘 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Svada

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8