A12275 | Vasya and Endless Credits
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya wants to buy himself a nice new car. Unfortunately, he lacks some money. Currently he has exactly 0 burles.
However, the local bank has $n$ credit offers. Each offer can be described with three numbers $a_i$ , $b_i$ and $k_i$ . Offers are numbered from $1$ to $n$ . If Vasya takes the $i$ -th offer, then the bank gives him $a_i$ burles at the beginning of the month and then Vasya pays bank $b_i$ burles at the end of each month for the next $k_i$ months (including the month he activated the offer). Vasya can take the offers any order he wants.
Each month Vasya can take no more than one credit offer. Also each credit offer can not be used more than once. Several credits can be active at the same time. It implies that Vasya pays bank the sum of $b_i$ over all the $i$ of active credits at the end of each month.
Vasya wants to buy a car in the middle of some month. He just takes all the money he currently has and buys the car of that exact price.
Vasya don't really care what he'll have to pay the bank back after he buys a car. He just goes out of the country on his car so that the bank can't find him anymore.
What is the maximum price that car can have?
However, the local bank has $n$ credit offers. Each offer can be described with three numbers $a_i$ , $b_i$ and $k_i$ . Offers are numbered from $1$ to $n$ . If Vasya takes the $i$ -th offer, then the bank gives him $a_i$ burles at the beginning of the month and then Vasya pays bank $b_i$ burles at the end of each month for the next $k_i$ months (including the month he activated the offer). Vasya can take the offers any order he wants.
Each month Vasya can take no more than one credit offer. Also each credit offer can not be used more than once. Several credits can be active at the same time. It implies that Vasya pays bank the sum of $b_i$ over all the $i$ of active credits at the end of each month.
Vasya wants to buy a car in the middle of some month. He just takes all the money he currently has and buys the car of that exact price.
Vasya don't really care what he'll have to pay the bank back after he buys a car. He just goes out of the country on his car so that the bank can't find him anymore.
What is the maximum price that car can have?
输入格式
The first line contains one integer $n$ ( $1 \le n \le 500$ ) — the number of credit offers.
Each of the next $n$ lines contains three integers $a_i$ , $b_i$ and $k_i$ ( $1 \le a_i, b_i, k_i \le 10^9$ ).
Each of the next $n$ lines contains three integers $a_i$ , $b_i$ and $k_i$ ( $1 \le a_i, b_i, k_i \le 10^9$ ).
输出格式
Print one integer — the maximum price of the car.
输入输出样例
输入 #1
4 10 9 2 20 33 1 30 115 1 5 3 2
输出 #1
32
输入 #2
3 40 1 2 1000 1100 5 300 2 1
输出 #2
1337
In the first example, the following sequence of offers taken is optimal: 4 $\rightarrow$ 3.
The amount of burles Vasya has changes the following way: 5 $\rightarrow$ 32 $\rightarrow$ -86 $\rightarrow$ .... He takes the money he has in the middle of the second month (32 burles) and buys the car.
The negative amount of money means that Vasya has to pay the bank that amount of burles.
In the second example, the following sequence of offers taken is optimal: 3 $\rightarrow$ 1 $\rightarrow$ 2.
The amount of burles Vasya has changes the following way: 0 $\rightarrow$ 300 $\rightarrow$ 338 $\rightarrow$ 1337 $\rightarrow$ 236 $\rightarrow$ -866 $\rightarrow$ ....
The amount of burles Vasya has changes the following way: 5 $\rightarrow$ 32 $\rightarrow$ -86 $\rightarrow$ .... He takes the money he has in the middle of the second month (32 burles) and buys the car.
The negative amount of money means that Vasya has to pay the bank that amount of burles.
In the second example, the following sequence of offers taken is optimal: 3 $\rightarrow$ 1 $\rightarrow$ 2.
The amount of burles Vasya has changes the following way: 0 $\rightarrow$ 300 $\rightarrow$ 338 $\rightarrow$ 1337 $\rightarrow$ 236 $\rightarrow$ -866 $\rightarrow$ ....
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted