题意:有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<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 505
#define nm 20005
#define pi 3.1415926535897931
const ll inf=1e16;
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
int n;
ll ans,d[NM][NM];
struct tmp{
ll a,b,k;
bool operator<(const tmp&o)const{return b>o.b;}
}a[NM];
int main(){
n=read();
inc(i,1,n)a[i]=tmp{read(),read(),read()};
sort(a+1,a+1+n);
inc(i,1,n){
inc(j,0,i){
d[i][j]=d[i-1][j];
if(j>0)d[i][j]=max(d[i][j],d[i-1][j-1]+a[i].a-(j-1)*a[i].b);
d[i][j]=max(d[i][j],d[i-1][j]+a[i].a-a[i].k*a[i].b);
}
}
//inc(i,1,n){inc(j,0,i)printf("%lld ",d[i][j]);putchar('\n');}
inc(i,1,n)ans=max(ans,d[n][i]);
return 0*printf("%lld\n",ans);
}
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 → ....