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

Sails

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

의견: 0

설명

ZAGREB – CROATIA
AUGUST 15 – 22

COMPETITION DAY 1 – SAILS

SAILS
A new pirate sailing ship is being built. The ship has N masts (poles) divided into unit sized segments – the
height of a mast is equal to the number of its segments. Each mast is fitted with a number of sails and each sail
exactly fits into one segment. Sails on one mast can be arbitrarily distributed among different segments, but each
segment can be fitted with at most one sail.
Different configurations of sails generate different amounts of thrust when exposed to the wind. Sails in front of
other sails at the same height get less wind and contribute less thrust. For each sail we define its inefficiency as
the total number of sails that are behind this sail and at the same height. Note that "in front of" and "behind"
relate to the orientation of the ship: in the figure below, "in front of" means to the left, and "behind" means to
the right.
The total inefficiency of a configuration is the sum of the inefficiencies of all individual sails.
front

back
This ship has 6 masts, of heights 3, 5, 4, 2, 4 and 3 from front (left side of image) to back.
This distribution of sails gives a total inefficiency of 10. The individual inefficiency of each sail is written inside the sail.
TASK
Write a program that, given the height and the number of sails on each of the N masts, determines the smallest
possible total inefficiency.

EXAMPLE

제약
입력 형식

The first line of input contains an integer N (2 ≤ N ≤ 100 000), the number of masts on the ship.
Each of the following N lines contains two integers H and K (1 ≤ H ≤ 100 000, 1 ≤ K ≤ H), the height and the
number of sails on the corresponding mast. Masts are given in order from the front to the back of the ship.

6
3 2
5 3
4 1
2 1
4 3
3 2

출력 형식

Output should consist of a single integer, the smallest possible total inefficiency.
Note: use a 64-bit integer type to calculate and output the result (long long in C/C++, int64 in Pascal).
GRADING
In test cases worth a total of 25 points, the total number of ways to arrange the sails will be at most 1 000 000.

ZAGREB – CROATIA
AUGUST 15 – 22

COMPETITION DAY 1 – SAILS

10

This example corresponds to the
figure on the previous page.

문제 정보

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

출처 IOI 2007

평가 및 의견

Sails

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

Log in to rate problems.

개별 의견

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

풀이 제출

Sails

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