Submission #1026087

#TimeUsernameProblemLanguageResultExecution timeMemory
1026087coolsentenceidontrememberCloud Computing (CEOI18_clo)C++17
100 / 100
610 ms2140 KiB
#include<bits/stdc++.h>

#pragma GCC optimize("O3", "unroll-loops")


#define ll long long
#define ld long double
#define ff first
#define ss second
#define db double
#define time_begin() auto begin = chrono::high_resolution_clock::now()
#define time_end() auto end = chrono::high_resolution_clock::now(); auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end-begin); auto sec = elapsed.count() * 1e-9; cerr << "\n\nExecution time: " << sec << " seconds";
#define check_time() cerr << "\nStatus : "; if (sec>1) cerr << "Time Limit Exceeded 1!!!1!111"; else cerr << "You good brother"

using namespace std;

void setIO(string s = ""){
 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cout.tie(nullptr);
 if (!s.empty()){
	freopen((s+".in").c_str(), "r", stdin);
	freopen((s+".out").c_str(), "w", stdout);
	}
}

const auto inf = LLONG_MAX;
const ll mod = 1e9 + 7;


ll pow_mod(ll a, ll b, ll m = mod){
	if (!a) return 0;
	a %= mod; ll res = 1;
	for (;b;b>>=1, a = (a*a)%mod){
		if (b&1) res = (res*a)%mod;
	}
	return res;
}


struct obj{
	bool computer;
	int core;
	int clock;
	ll profit;
	
};

bool cmp(const obj &a, const obj&b){
	if (a.clock != b.clock) return a.clock > b.clock;
	else if (a.computer != b.computer) return (a.computer);
	else if (!a.computer) return a.profit > b.profit;
	else return a.profit < b.profit; 
}






int main(){
	setIO();
    int n;
    cin >> n;
    vector<obj> v;
    int total_core = 0;
    for (int i=1; i <= n; i++){
    	obj c;
    	cin >> c.core >> c.clock >> c.profit;
    	c.computer = 1;
    	total_core += c.core;
    	v.push_back(c);
	}
	int m;
	cin >> m;
	for (int i = 1; i <= m; i++){
		obj o;
		cin >> o.core >> o.clock >> o.profit;
		o.computer = 0;
		v.push_back(o);
	}
	sort(v.begin(), v.end(), cmp);
	
	vector<ll> dp1(total_core+1, -inf);
	
	dp1[0] = 0;
	for (int i = 0; i < n+m; i++){
		obj cur = v[i];
		vector<ll> dp2(dp1);
		if (cur.computer) cur.profit = -cur.profit;
		else cur.core = -cur.core;
		for (int c = 0; c <= total_core; c++){
			int past = c - cur.core;
			if (past >= 0 && past <= total_core && dp1[past] != -inf){
			//	cout << i << ' ' << c << ' ' << past << ' ' << cur.profit << ' ' << dp1[past] << '\n';
				dp2[c] = max(dp2[c], dp1[past] + cur.profit);
			}
		}
	dp1 = dp2;	
		
	}
	cout << *max_element(dp1.begin(), dp1.end()) << '\n';
	return 0;
}

Compilation message (stderr)

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