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

Balancing Bacteria

Gold IV 골드 IV
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John has \(N\) (\(1\le N\le 2\cdot 10^5\)) patches of grass in a line, where
patch \(i\) has a level of bacteria that differs by \(a_i\) from that of healthy
grass (\(-10^{15}\le a_i \le 10^{15}\)). For example, if \(a_i = -3\), then patch
\(i\) has a level of bacteria 3 lower than normal, and would need exactly 3
additional units of bacteria added to raise it to the point where it is
considered healthy.

Farmer John wants to ensure every patch of grass is corrected to have a healthy
level of bacteria. Conveniently, he owns two brands of pesticide that he can
spray on his field, one that adds bacteria and one that removes bacteria. When
Farmer John sprays either type of pesticide, he stands in patch \(N\) (the
rightmost patch) and selects a power level \(L\) for his sprayer (\(1 \leq L \leq N\)).

The sprayer has the most impact on patches near Farmer John, with diminishing
effect farther away. If Farmer John chooses the pesticide that adds bacteria,
then \(L\) units of bacteria will be added to patch \(N\), \(L-1\) units to patch
\(N-1\), \(L-2\) units to patch \(N-2\), and so on. Patches \(1 \ldots N-L\) will
receive no bacteria, since the sprayer isn't set to a level powerful enough to
reach them. Similarly, if Farmer John chooses the pesticide that removes
bacteria, then \(L\) units of bacteria will be removed from patch \(N\), \(L-1\) units
will be removed from patch \(N-1\), and so on. Again, patches \(1 \ldots N-L\) will
be unaffected.

Find the minimum number of times Farmer John has to apply his sprayer such that
every patch of grass has the recommended value of bacteria for healthy grass. It
is guaranteed that the answer is at most \(10^9\).

Note that the large size of integers involved in this problem may require the
use of 64-bit integer data types (e.g., a "long long" in C/C++).

Problem credits: Rohin Garg

제약

SCORING

  • Inputs 3-5: \(N \le 10^3\), the answer is at most \(10^3\)
  • Inputs 6-10: \(N \le 10^3\)
  • Inputs 11-15: No additional constraints.

Problem credits: Rohin Garg

입력 형식

The first line contains \(N\).

The second line contains \(N\) integers \(a_1\dots a_N\), the initial bacteria
levels of each patch of grass.

출력 형식

The minimum number of applications necessary to make every patch of grass have
the recommended value of bacteria for healthy grass.

예제 1
입력
2
-1 3
출력
6
설명

Use the type of pesticide that removes bacteria, at a power level of 1, five
times. Then use the type of pesticide that adds bacteria, with a power level of
\(2\), one time.

예제 2
입력
5
1 3 -2 -7 5
출력
26
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2023-2024 > January > Bronze

태그

평가 및 의견

Balancing Bacteria

개요
출제자 난이도 Gold IV 골드 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Balancing Bacteria

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