Submission #148091

#TimeUsernameProblemLanguageResultExecution timeMemory
148091WhipppedCreamCloud Computing (CEOI18_clo)C++17
100 / 100
396 ms1400 KiB
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int lim = 1e5+5;

ll dp[lim];

struct node
{
	int c, v, f, t;
	node(int _c, int _v, int _f, int _t)
	{
		c = _c; v = _v; f = _f; t = _t;
	}
	bool operator < (node other) const
	{
		if(f != other.f) return f> other.f;
		return t< other.t;
	}
};

vector<node> items;
int n, m;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i<= n; i++)
	{
		int c, v, f; scanf("%d %d %d", &c, &f, &v);
		items.pb(node(c, v, f, -1));
	}
	scanf("%d", &m);
	for(int i = 1; i<= m; i++)
	{
		int c, v, f; scanf("%d %d %d", &c, &f, &v);
		items.pb(node(c, v, f, 1));
	}
	sort(items.begin(), items.end());
	for(int i = 1; i<= 1e5; i++) dp[i] = -1e15;
	dp[0] = 0;
	for(auto pong : items)
	{
		int w = -pong.c*pong.t;
		int v = pong.v*pong.t;
		//printf("%d %d\n", w, v);
		if(w> 0)
		{
			//buy
			for(int i = 1e5; i>= w; i--)
			{
				dp[i] = max(dp[i], v+dp[i-w]);
			}
		}
		else
		{
			//sell
			for(int i = 0; i<= ((int)1e5+w); i++)
			{
				dp[i] = max(dp[i], v+dp[i-w]);
			}
		}
		//printf("dp[1] = %lld\n", dp[1]);
	}
	ll best = 0;
	for(int i = 0; i<= 1e5; i++) best = max(best, dp[i]);
	printf("%lld\n", best);
	//for(int i = 0; i<= 1e5; i++) if(dp[i] == best) printf("%d\n", i);
	return 0;
}

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
clo.cpp:35:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int c, v, f; scanf("%d %d %d", &c, &f, &v);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &m);
  ~~~~~^~~~~~~~~~
clo.cpp:41:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int c, v, f; scanf("%d %d %d", &c, &f, &v);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...