No.798 Collection
Problem Statement
A new shop will open tomorrow in the town where yuki lives.
yuki has decided to visit the shop every day starting tomorrow and to collect all of its items by buying one item per day ($1$ item every $1$ day).
Since yuki is the only resident of the town, no one else ever buys the shop's items.
The shop sells $N$ items, and the price of the $i$-th item is initially $A_i$ yen.
However, the price of each item rises by $B_i$ yen every $1$ day.
That is, buying item $i$ on day $d$ after the opening costs $A_i+B_i \times d$ yen.
The opening day itself is regarded as day $0$ after the opening.
Also, each item has only $1$ unit in stock, and the same item cannot be bought $2$ times.
The shop runs a campaign on days when the number of days elapsed since the opening is odd (days $1$, $3$, $5$, ... after the opening).
A person who buys an item on a campaign day may, in addition to the purchased item, buy exactly $1$ other item of their choice for $0$ yen, regardless of its price.
yuki wants to collect all the items in the shop for as little money as possible by choosing the order of purchases wisely.
Find the minimum amount of money required to collect all $N$ items.
Input
$N$ $A_1\ B_1$ $A_2\ B_2$ $.$ $.$ $A_N\ B_N$
The $1$st line gives the number of items $N$.
The following $N$ lines, starting from the $2$nd line, give the information about the items.
Among them, the $i$-th line gives the initial price $A_i$ of item $i$ and the integer $B_i$, separated by a space.
Constraints
- $1 \le N \le 2000$
- $1 \le A_i,B_i \le 10^5\ (i=1, 2, \dots, N)$
- All inputs are integers.
Output
Output the minimum amount of money required to collect the $N$ items. Print a newline at the end.
Sample
Sample 1
Input
3 6 8 2 9 4 7
Output
13
In this case, the optimal actions for yuki are as follows.
- Day $0$: Pay $2+9 \times 0=2$ yen to buy item $2$.
- Day $1$: Pay $4+7 \times 1=11$ yen to buy item $3$.
- Since this is an odd-numbered day after the opening, buy item $1$ for free through the campaign.
Sample 2
Input
2 6 2 3 3
Output
11
It is optimal to buy item $2$ on day $0$ and item $1$ on day $1$.
Note that yuki cannot take actions such as the following.
- Buying no item on day $0$, then buying item $2$ on day $1$ and buying item $1$ for $0$ yen through the campaign.
- Buying item $2$ on day $0$, buying item $2$ again on day $1$, and buying item $1$ for $0$ yen through the campaign.
Sample 3
Input
8 3 13 18 8 3 14 1 18 3 3 18 12 10 18 15 19
Output
169
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ikd
37zigen