-
Notifications
You must be signed in to change notification settings - Fork 11
/
2019-B-B.cpp
63 lines (46 loc) · 1.29 KB
/
2019-B-B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
using namespace std;
#define ms(x,v) memset(x,(v), sizeof(x))
#define msn(x,v,n) memset(x,(v),sizeof(x[0]) * n)
#define INF 0x3f3f3f3f
typedef long long LL;
const int MAXN = 100 + 3;
int T;
int n;
struct Node{
LL s,l,e;
};
Node stone[MAXN];
inline bool cmp(const Node& a,const Node& b){
auto va = a.e + b.e - b.l * a.s;
auto vb = a.e + b.e - a.l * b.s;
return va > vb;
}
LL dp[MAXN*MAXN];
int main(int argc, char const *argv[])
{
ios :: sync_with_stdio(0);
cin.tie(0);
std::cout.precision(8);
std::cout.setf( std::ios::fixed, std:: ios::floatfield );
cin >> T;
for(int t =1; t <= T ; ++t)
{
cin >> n ;
for(int i=0 ; i< n ; ++i)
cin >>stone[i].s >> stone[i].e >> stone[i].l;
sort(stone,stone+n,cmp);
ms(dp,0);
int sum_time =0;
for(int i=0 ; i<n ; ++i){
sum_time += stone[i].s;
for(LL time = sum_time ; time>=stone[i].s ; --time){
auto value = stone[i].e - stone[i].l * (time - stone[i].s);
if(value <=0)continue;
dp[time] = max(dp[time],dp[time-stone[i].s] + value);
}
}
cout << "Case #"<<t << ": " << *max_element(dp,dp+sum_time+1) << "\n";
}
return 0;
}