답안 #293905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293905 2020-09-08T13:40:09 Z arnold518 Two Dishes (JOI19_dishes) C++14
10 / 100
10000 ms 25184 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e6;

struct Point
{
	int x, y; ll w;
};
vector<Point> V;

int N, M;
ll ans;

ll A[MAXN+10], S[MAXN+10], P[MAXN+10], B[MAXN+10], T[MAXN+10], Q[MAXN+10];

ll dp[MAXN+10];

int main()
{
	scanf("%d%d", &N, &M);
	for(int i=1; i<=N; i++) scanf("%lld%lld%lld", &A[i], &S[i], &P[i]), A[i]+=A[i-1];
	for(int i=1; i<=M; i++) scanf("%lld%lld%lld", &B[i], &T[i], &Q[i]), B[i]+=B[i-1];

	for(int i=1; i<=N; i++)
	{
		int t=upper_bound(B, B+M+1, S[i]-A[i])-B-1;
		if(t<0) continue;
		if(t==M) { ans+=P[i]; continue; }
		int x=i, y=t;
		x--; y++;
		V.push_back({x, y, -P[i]}); ans+=P[i];
	}

	for(int i=1; i<=M; i++)
	{
		int t=upper_bound(A, A+N+1, T[i]-B[i])-A-1;
		if(t<0) continue;
		if(t==N) { ans+=Q[i]; continue; }
		int y=i, x=t;
		V.push_back({x, y, Q[i]});
	}

	sort(V.begin(), V.end(), [&](const Point &p, const Point &q)
	{
		if(p.x!=q.x) return p.x<q.x;
		if(p.y!=q.y) return p.y>q.y;
		return p.w>q.w;
	});

	for(int i=0; i<V.size(); i++)
	{
		for(int j=V[i].y; j<=M; j++) dp[j]+=V[i].w;
		for(int j=1; j<=M; j++) dp[j]=max(dp[j], dp[j-1]);
	}
	printf("%lld\n", dp[M]+ans);
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for(int i=0; i<V.size(); i++)
      |               ~^~~~~~~~~
dishes.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:26:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  for(int i=1; i<=N; i++) scanf("%lld%lld%lld", &A[i], &S[i], &P[i]), A[i]+=A[i-1];
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:27:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  for(int i=1; i<=M; i++) scanf("%lld%lld%lld", &B[i], &T[i], &Q[i]), B[i]+=B[i-1];
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10086 ms 20840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 416 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 416 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 20 ms 700 KB Output is correct
18 Correct 19 ms 640 KB Output is correct
19 Correct 34 ms 760 KB Output is correct
20 Correct 17 ms 640 KB Output is correct
21 Correct 30 ms 640 KB Output is correct
22 Correct 39 ms 640 KB Output is correct
23 Correct 34 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 416 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 20 ms 700 KB Output is correct
18 Correct 19 ms 640 KB Output is correct
19 Correct 34 ms 760 KB Output is correct
20 Correct 17 ms 640 KB Output is correct
21 Correct 30 ms 640 KB Output is correct
22 Correct 39 ms 640 KB Output is correct
23 Correct 34 ms 640 KB Output is correct
24 Execution timed out 10009 ms 25184 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 416 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 20 ms 700 KB Output is correct
18 Correct 19 ms 640 KB Output is correct
19 Correct 34 ms 760 KB Output is correct
20 Correct 17 ms 640 KB Output is correct
21 Correct 30 ms 640 KB Output is correct
22 Correct 39 ms 640 KB Output is correct
23 Correct 34 ms 640 KB Output is correct
24 Execution timed out 10009 ms 25184 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 416 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 20 ms 700 KB Output is correct
18 Correct 19 ms 640 KB Output is correct
19 Correct 34 ms 760 KB Output is correct
20 Correct 17 ms 640 KB Output is correct
21 Correct 30 ms 640 KB Output is correct
22 Correct 39 ms 640 KB Output is correct
23 Correct 34 ms 640 KB Output is correct
24 Execution timed out 10009 ms 25184 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10086 ms 20840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10086 ms 20840 KB Time limit exceeded
2 Halted 0 ms 0 KB -