Submission #673650

#TimeUsernameProblemLanguageResultExecution timeMemory
673650vjudge1Cloud Computing (CEOI18_clo)C++14
100 / 100
1591 ms3640 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pb push_back
#define all(val) val.begin(), val.end()
#define db(val) "[" #val " = " << (val) << "] "

const int N = 2005;
const int C = 50;
const ll INF = 1e15;

struct Node {
	int c, f, w;
	bool operator < (const Node &o) {
		if (f != o.f) return f > o.f;
		return c > o.c;
	}
	Node(int c, int f, int w): c(c), f(f), w(w) {}
};

ll dp[2][100 * N];
int n, m;
vector<Node> a;

void MAX(ll &a, ll b) {
	if (a < b) a = b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1, c, f, w; i <= n; i++) {
    	cin >> c >> f >> w;
    	a.pb(Node(c, f, -w));
    }
    cin >> m;
    for (int i = 1, c, f, w; i <= m; i++) {
    	cin >> c >> f >> w;
    	a.pb(Node(-c, f, w));
    }
    sort(all(a));
    fill(dp[0], dp[0] + (n + m) * C + 1,  -INF);
    dp[0][0] = 0;
    for (int i = 0; i < n + m; i++) {
    	int cur = i & 1, nxt = cur ^ 1;
    	fill(dp[nxt], dp[nxt] + (n + m) * C + 1, -INF);
    	for (int j = 0; j <= (n + m) * C; j++)
    		if (dp[cur][j] != -INF) {
    			MAX(dp[nxt][j], dp[cur][j]);
    			if (j + a[i].c >= 0)
    				MAX(dp[nxt][j + a[i].c], dp[cur][j] + a[i].w);
    		}
    }
    ll res = 0;
    for (int j = 0; j <= (n + m) * C; j++)
		MAX(res, dp[(n + m) & 1][j]);    	
    cout << res;
    
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...