Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 505;
- struct TYPE_OF_BET {
- struct Bet {
- int a, b, c;
- Bet(int a, int b): a(a), b(b), c(a + b) {}
- };
- vector<Bet> bets;
- void add(int a, int b) {
- bets.push_back(Bet(a,b));
- }
- vector<int> d[2];
- int t, nt;
- void calcDP() {
- d[0].resize(2*N*N);
- d[1].resize(2*N*N);
- t = 0, nt = 1;
- for(Bet bet : bets) {
- for(int x = 0; x < 2 * N * N; ++x) {
- d[nt][x] = max(d[t][x], x - bet.c >= 0 ? d[t][x - bet.c] + bet.b : 0);
- }
- swap(t, nt);
- }
- }
- int get(int x) {
- return d[t].at(x);
- }
- } A[3];
- void solve() {
- int n;
- scanf("%d\n",&n);
- for(int a, b, i = 0; i < n; ++i) {
- char t;
- scanf("%c %d %d\n",&t,&a,&b);
- if ( t == 'L' ) A[0].add(a, b);
- if ( t == 'W' ) A[1].add(a, b);
- if ( t == 'D' ) A[2].add(a, b);
- }
- for(int i = 0; i < 3; ++i) {
- A[i].calcDP();
- }
- int best = 0;
- for(int x = 0; x < 2 * N * N; ++x) {
- best = max(best, A[0].get(x) + A[1].get(x) + A[2].get(x) - x);
- }
- printf("%d\n", best);
- }
- int main() {
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement