Submission #502461

#TimeUsernameProblemLanguageResultExecution timeMemory
502461wwddCloud Computing (CEOI18_clo)C++14
100 / 100
328 ms2180 KiB
// bruh this time complexity is so bad
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
const ll INFL = 1e18;
struct OP {
	ll op,kt,val,so;
	OP(ll op_, ll kt_, ll val_, ll so_): op(op_), kt(kt_), val(val_), so(so_) {
	}
	bool operator<(const OP& ot) const {
		if(so != ot.so) {return so > ot.so;}
		return op > ot.op;
	};

};
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	vector<OP> ops;
	ll n;
	cin >> n;
	for(int i=0;i<n;i++) {
		ll kt,so,val;
		cin >> kt >> so >> val;
		ops.emplace_back(1,kt,val,so);
	}
	ll m;
	cin >> m;
	for(int i=0;i<m;i++) {
		ll kt,so,val;
		cin >> kt >> so >> val;
		ops.emplace_back(-1,kt,val,so);
	}
	sort(ops.begin(),ops.end());
	vector<ll> dp;
	dp.push_back(0);
	for(const auto& op: ops) {
		if(op.op == 1) {
			dp.resize(dp.size()+op.kt,-INFL);
			for(int i=dp.size()-1;i>=op.kt;i--) {
				dp[i] = max(dp[i],dp[i-op.kt]-op.val);
			}
		} else {
			for(int i=0;i+op.kt<dp.size();i++) {
				dp[i] = max(dp[i],dp[i+op.kt]+op.val);
			}
		}
	}
	ll ans = 0;
	for(int i=0;i<dp.size();i++) {
		ans = max(ans,dp[i]);
	}
	cout << ans << '\n';
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:44:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    for(int i=0;i+op.kt<dp.size();i++) {
      |                ~~~~~~~^~~~~~~~~~
clo.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i=0;i<dp.size();i++) {
      |              ~^~~~~~~~~~
#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...