Submission #1300166

#TimeUsernameProblemLanguageResultExecution timeMemory
1300166pete555Cloud Computing (CEOI18_clo)C++20
0 / 100
1 ms720 KiB
#include<bits/stdc++.h>
using namespace std;

#define pi pair<int,int>
#define ll long long
#define pb push_back
#define pf push_front

void fileIO(string filename) {
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

struct Transaction {
	int cores;
	int rate;
	int price;
	bool operator<(const Transaction &other) {
		return rate > other.rate;
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(false);
	//fileIO("");
	int total_cores = 0;
	vector<Transaction> Transactions;

	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		Transaction x;
		cin >> x.cores >> x.rate >> x.price;
		x.price = -x.price;
		Transactions.pb(x);
		total_cores += x.cores;
	}

	int m;
	cin >> m;
	for(int i = 0; i < m; i++) {
		Transaction x;
		cin >> x.cores >> x.rate >> x.price;
		x.cores = -x.cores;
		Transactions.pb(x);
		total_cores += x.cores;
	}

	sort(Transactions.begin(), Transactions.end());

	vector<ll> prev(total_cores + 1, LLONG_MIN / 2);
	prev[0] = 0;
	for(Transaction x : Transactions) {
		vector<ll> dp(prev);
		for(int i = 0; i <= total_cores; i++) {
			int j = i - x.cores;
			if(0 <= j && j <= total_cores) {
				dp[i] = max(dp[i], prev[j] + x.price);
			}
		}
		prev = dp;
	}	

	cout << *max_element(prev.begin(), prev.end()) << '\n';
}

Compilation message (stderr)

clo.cpp: In function 'void fileIO(std::string)':
clo.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen((filename + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen((filename + ".out").c_str(), "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...