Submission #242959

# Submission time Handle Problem Language Result Execution time Memory
242959 2020-06-30T02:41:15 Z Lawliet Cloud Computing (CEOI18_clo) C++17
54 / 100
584 ms 2040 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;

const int MAXN = 4010;
const int MAXS = 2000*50;

struct event
{
	int type, cmp;
	int qtd, price;

	event(int t, int q, int p, int c)
		: type(t), qtd(q), price(p), cmp(c) {}

	bool operator < (event a)
	{
		if( cmp != a.cmp ) return cmp < a.cmp;
		return type < a.type;
	}
};

int n, m;

lli dp[2][MAXS];

vector<event> v;

int main()
{
	scanf("%d",&n);

	int sum = 0;

	for(int i = 1 ; i <= n ; i++)
	{
		int q, c, p;
		scanf("%d %d %d",&q,&c,&p);

		sum += q;

		v.push_back( event( 0 , q , p , c ) );
	}

	scanf("%d",&m);

	for(int i = 1 ; i <= m ; i++)
	{
		int q, c, p;
		scanf("%d %d %d",&q,&c,&p);

		v.push_back( event( 1 , q , p , c ) );
	}

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

	for(int i = 1 ; i <= n + m ; i++)
	{
		int qtd = v[i - 1].qtd;
		int type = v[i - 1].type;
		int price = v[i - 1].price;

		for(int j = 0 ; j <= sum ; j++)
		{
			lli& ans = dp[i%2][j];
			ans = dp[1 - i%2][j];

			if( type == 0 ) ans = max( ans , dp[1 - i%2][j + qtd] - price );
			else if( j >= qtd ) ans = max( ans , dp[1 - i%2][j - qtd] + price );
		}
	}

	printf("%lld\n",dp[ (n + m)%2 ][0]);
}

Compilation message

clo.cpp: In constructor 'event::event(int, int, int, int)':
clo.cpp:12:11: warning: 'event::price' will be initialized after [-Wreorder]
  int qtd, price;
           ^~~~~
clo.cpp:11:12: warning:   'int event::cmp' [-Wreorder]
  int type, cmp;
            ^~~
clo.cpp:14:2: warning:   when initialized here [-Wreorder]
  event(int t, int q, int p, int c)
  ^~~~~
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:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&q,&c,&p);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
clo.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&m);
  ~~~~~^~~~~~~~~
clo.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&q,&c,&p);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 8 ms 512 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 38 ms 768 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 167 ms 1280 KB Output is correct
8 Correct 36 ms 640 KB Output is correct
9 Incorrect 267 ms 1792 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 39 ms 768 KB Output is correct
4 Correct 12 ms 512 KB Output is correct
5 Correct 584 ms 1920 KB Output is correct
6 Correct 570 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 8 ms 512 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 38 ms 768 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 167 ms 1280 KB Output is correct
16 Correct 36 ms 640 KB Output is correct
17 Incorrect 267 ms 1792 KB Output isn't correct