제출 #139419

#제출 시각아이디문제언어결과실행 시간메모리
139419luciocfCloud Computing (CEOI18_clo)C++14
100 / 100
1816 ms3704 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 2e3+10;
const int maxc = 51;
const ll inf = 2e18+10;

struct Obj
{
	int c, f, v;
} a[maxn], b[maxn];

int n, m;

ll dp[2][maxn][2*maxc];

void upd(ll &a, ll b)
{
	a = max(a, b);
}

bool comp(Obj a, Obj b)
{
	return a.f > b.f;
}

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

	for (int i = 1; i <= n; i++)
		scanf("%d %d %d", &a[i].c, &a[i].f, &a[i].v);

	scanf("%d", &m);

	for (int i = 1; i <= m; i++)
		scanf("%d %d %d", &b[i].c, &b[i].f, &b[i].v);

	sort(a+1, a+n+1, comp);
	sort(b+1, b+m+1, comp);

	for (int i = n; i >= 0; i--)
	{
		int at = i%2, pre = (i+1)%2;

		for (int j = m; j >= 1; j--)
		{
			for (int c = 2*maxc-1; c >= 0; c--)
			{
				if (a[i+1].f < b[j].f && c > 0 && c < b[j].c)
				{
					upd(dp[at][j][c], dp[at][j+1][c]);
					continue;
				}

				upd(dp[at][j][c], dp[pre][j][c]);

				upd(dp[at][j][c], dp[at][j+1][c]);

				if (c >= b[j].c)
					upd(dp[at][j][c], 1ll*b[j].v + dp[at][j+1][c-b[j].c]);

				if (i < n && c < maxc && a[i+1].f >= b[j].f)
					upd(dp[at][j][c], dp[pre][j][c+a[i+1].c] - 1ll*a[i+1].v);

			}
		}
	}

	printf("%lld\n", max(0ll, dp[0][1][0]));
}

컴파일 시 표준 에러 (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:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a[i].c, &a[i].f, &a[i].v);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &m);
  ~~~~~^~~~~~~~~~
clo.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &b[i].c, &b[i].f, &b[i].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...