답안 #123280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123280 2019-07-01T05:39:44 Z 이온조(#3019) Two Dishes (JOI19_dishes) C++14
0 / 100
220 ms 10512 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1LL * 1e18;
int A[1000009], B[1000009], P[1000009], Q[1000009];
long long S[1000009], T[1000009], PB[1000009], PQ[1000009];

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

	bool S1 = (S[1] == T[1]);
	for(int i=2; i<=N; i++) if(S[i] != S[i-1]) S1 = 0;
	for(int i=2; i<=M; i++) if(T[i] != T[i-1]) S1 = 0;
	if(S1) {
		for(int i=1; i<=M; i++) PB[i] = PB[i-1] + B[i], PQ[i] = PQ[i-1] + Q[i];
		long long x = S[1], ans = -INF, s = 0;
		for(int i=1; i<=N+1; i++) {
			int l = 0, r = M;
			while(l <= r) {
				int m = l+r >> 1;
				if(PB[m] <= x) l = m+1;
				else r = m-1;
			}
			if(PB[l-1] + A[i] > x) ans = max(ans, s + PQ[l-1]);

			if(i == N+1) break;
			x -= A[i]; s += P[i];
		}
		printf("%lld", ans);
	}
	return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:22:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int m = l+r >> 1;
             ~^~
dishes.cpp:9:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, M; scanf("%d%d",&N,&M);
            ~~~~~^~~~~~~~~~~~~~
dishes.cpp:10:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d%lld%d", &A[i], &S[i], &P[i]);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:11:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=M; i++) scanf("%d%lld%d", &B[i], &T[i], &Q[i]);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 10512 KB Output is correct
2 Incorrect 220 ms 10220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 10512 KB Output is correct
2 Incorrect 220 ms 10220 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 10512 KB Output is correct
2 Incorrect 220 ms 10220 KB Output isn't correct
3 Halted 0 ms 0 KB -