题意:有n种贷款服务,每种贷款可以立即获得ai元,但是在之后的ki个月每个月底都要支付bi元,一个月只能贷款一次,问在所有时刻中手上最多能有多少钱(他可以在任何时候跑路exm??
直接就抄题解了。。
原题解是说,让n个月和n种贷款做二分图最大权匹配,连的边权直接就是对应月选择对应贷款到跑路所获的收益。。
然而出题人好像并没有想到这可
假设贷款都还没支付ki个月就跑路了,那么对选择固定贷款的方案来说,将bi小的放在前面肯定更合适,所以考虑按b对方案进行排序,然后做一下DP就可以了。。对那些ki个月已经支付完的方案,显然他们得排在最前面,所以在DP转移的时候考虑一下把该方案放在最前面的情况就可以了。。
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━━━━━━━━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include
#include
#include
#include
#include
#include
F. Vasya and Endless Credits
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 ?
credit offers. Each offer can be described with three numbers ??, ?? and ??. Offers are numbered from 1 to ?. If Vasya takes the ?-th offer, then the bank gives him ?? burles at the beginning of the month and then Vasya pays bank ?? burles at the end of each month for the next ??
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 ??
over all the ?
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?
Input
The first line contains one integer ?
(1≤?≤500
) — the number of credit offers.
Each of the next ?
lines contains three integers ??, ?? and ?? (1≤??,??,??≤109
).
Output
Print one integer — the maximum price of the car.
Examples
Input
Copy
4 10 9 2 20 33 1 30 115 1 5 3 2
Output
Copy
32
Input
Copy
3 40 1 2 1000 1100 5 300 2 1
Output
Copy
1337
Note
In the first example, the following sequence of offers taken is optimal: 4 →
3.
The amount of burles Vasya has changes the following way: 5 →
32 → -86 →
.... 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 →
1 →
2.
The amount of burles Vasya has changes the following way: 0 →
300 → 338 → 1337 → 236 → -866 → ....