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

A. Balanced Diet

Unrated 레이팅 미적용
난이도
2s
시간 제한
1024MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Every day, Danny buys one sweet from the candy store and eats it. The store has \(m\) types of sweets, numbered from 1 to \(m\). Danny knows that a balanced diet is important and is applying this concept to his sweet purchasing. To each sweet type \(i\), he has assigned a target fraction, which is a real number \(fi\) (\(0 < f_{i} \le 1\)). He wants the fraction of sweets of type \(i\) among all sweets he has eaten to be roughly equal to \(f_{i}\). To be more precise, let \(s_{i}\) denote the number of sweets of type \(i\) that Danny has eaten, and let \(n\) = {P} {i} {s}}^{.} ^{We say the set of sweets is{balanced}{i} \(nf_{i} - 1 < s_{i} < nf_{i} + 1\). Danny has been buying and eating sweets for a while and during this entire time the set of sweets has been balanced. He is now wondering how many more sweets he can buy while still fulfilling this condition. Given the target fractions \(fi\) and the sequence of sweets he has eaten so far, determine how many more sweets he can buy and eat so that at any time the set of sweets is balanced.

제약
입력 형식

The input consists of three lines. The first line contains two integers \(m\) (\(1 \le m \le 10^{5}\)), which is the number of types of sweets, and \(k\) (\(0 \le k \le 10^{5}\)), which is the number of sweets Danny has already eaten. The second line contains \(m\) positive integers \(a\)1, . . . , a\(m\). These numbers are proportional to \(f\)1, . . . , f\(m\), that is, \(fi = ai\) P_{m} \(j=1\) {a} (\(1 \le bi \le m\)), where each \(bi\) denotes the type of sweet Danny bought and ate on the \(i^{th}\) day. It is guaranteed that every prefix of this sequence (including the whole sequence) is balanced.} . It is guaranteed that the sum of all \(aj\) is no larger than \(10^{5}\). The third line contains \(k\) integers \(b\)1, . . . , b_{k

출력 형식

Display the maximum number of additional sweets that Danny can buy and eat while keeping his diet continuously balanced. If there is no upper limit on the number of sweets, display the word forever.

예제 1
입력
6 5
2 1 6 3 5 3
1 2 5 3 5
출력
1

예제 2
입력
6 4
2 1 6 3 5 3
1 2 5 3
출력
forever

문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC World Finals 2016

평가 및 의견

A. Balanced Diet

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

A. Balanced Diet

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