Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <unordered_map>
- #include <numeric>
- #include <iomanip>
- using namespace std;
- #define pii pair<long long, long long>
- #define ll long long
- #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
- #define mp(x1, x2) ( make_pair(x1, x2) )
- const long long dx[4] = {1, 0, 0, -1}, dy[4] = {0, 1, -1, 0};
- const long long dl[2] = {1, -1};
- const long long MOD = 100000;
- const long long MAXN = 2005;
- int n, a, b;
- struct cow {
- int p;
- int c;
- int x;
- cow(){
- p = 0;
- c = 0;
- x = 0;
- }
- cow (int p_, int c_, int x_){
- p = p_;
- c = c_;
- x = x_;
- }
- };
- vector<cow> v;
- int dp[MAXN][2 * MAXN];
- bool operator<(cow const& cx, cow const& cy){
- if(cx.x != cy.x) return cx.x < cy.x;
- return (cx.p / (double) cx.c) > (cy.p / (double) cy.c);
- }
- int main(){
- FAST;
- cin >> n >> a >> b;
- for(int i = 0; i < n; i++){
- int p, c, x;
- cin >> p >> c >> x;
- v.push_back(cow(p, c, x));
- }
- sort(v.begin(), v.end());
- memset(dp, -1, sizeof dp);
- dp[0][a + b] = 0;
- for(int i = 0; i < n; i++){
- int p = v[i].p;
- int c = v[i].c;
- int x = v[i].x;
- for(int j = 0; j <= a + b; j++){
- if(dp[i][j] == -1) continue;
- dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
- if(j >= a + c * x){
- dp[i + 1][j - c * x] = max(dp[i + 1][j - c * x], dp[i][j] + p);
- }
- else if(j > a){
- int red = (j - a) / x;
- if(a >= (c - red)){
- dp[i + 1][a - (c - red)] = max(dp[i + 1][a - (c - red)], dp[i][j] + p);
- }
- }
- else if(j >= c){
- dp[i + 1][j - c] = max(dp[i + 1][j - c], dp[i][j] + p);
- }
- }
- }
- int maxe = 0;
- for(int i = 0; i <= a + b; i++){
- maxe = max(maxe, dp[n][i]);
- }
- cout << maxe << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement