Submission #1264401

#TimeUsernameProblemLanguageResultExecution timeMemory
1264401minggaCloud Computing (CEOI18_clo)C++20
54 / 100
502 ms3616 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 4005;
const int M = 2e5 + 7;
int n, m;
ll dp[2][M];

struct dak {
	int c, f, v;
	bool operator < (const dak& o) const {
		if(f == o.f) return v < o.v;
		return f < o.f;
	}
} a[N];

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n;
	for(int i = 1; i <= n; i++) {
		int c, f, v; cin >> c >> f >> v;
		a[i] = {-c, f, -v};
	}
	cin >> m;
	int totc = 0;
	for(int i = 1; i <= m; i++) {
		int c, f, v; cin >> c >> f >> v;
		a[i + n] = {c, f, v};
		totc += c;
	}
	n += m;
	sort(a + 1, a + n + 1);
	memset(dp, -0x3f, sizeof dp);
	dp[0][0] = 0;
	// for(int i = 1; i <= n; i++) {
	// 	cerr << a[i].c << ' ' << a[i].f << ' ' << a[i].v << ln;
	// }
	for(int i = 1; i <= n; i++) {
		int id = i & 1;
		for(int j = 0; j <= totc; j++) {
			dp[id][j] = dp[id ^ 1][j];
		}
		for(int j = 0; j <= totc; j++) {
			int nc = max(0, j + a[i].c);
			dp[id][nc] = max(dp[id][nc], dp[id ^ 1][j] + a[i].v);
		}
		// for(int j = 0; j <= totc; j++)
		// 	cerr << i << ' ' << j << ' ' << dp[id][j] << ln;
	}
	cout << dp[n & 1][0] << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:32:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:33:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...