Submission #528337

# Submission time Handle Problem Language Result Execution time Memory
528337 2022-02-20T05:10:59 Z fhvirus Two Dishes (JOI19_dishes) C++17
0 / 100
15 ms 10056 KB
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define AI(x) begin(x),end(x)
#ifdef OWO
#define debug(args...) SDF(#args, args)
#define OIU(args...) ostream& operator<<(ostream&O,args)
#define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;}
LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss)
template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));}
template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}
#else
#define debug(...) ((void)0)
#endif

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int N, M; cin >> N >> M;
	vector<int> A(N + 1), S(N + 1), P(N + 1);
	for (int i = 1; i <= N; ++i)
		cin >> A[i] >> S[i] >> P[i];
	vector<int> B(M + 1), T(M + 1), Q(M + 1);
	for (int i = 1; i <= M; ++i)
		cin >> B[i] >> T[i] >> Q[i];

	assert(N <= 5000 and M <= 5000);

	vector<int64_t> preA(N + 1, 0);
	for (int i = 1; i <= N; ++i)
		preA[i] = preA[i - 1] + A[i];

	vector<int64_t> preB(M + 1, 0);
	for (int i = 1; i <= M; ++i)
		preB[i] = preB[i - 1] + B[i];

	int64_t ans = LLONG_MIN;
	vector<vector<int64_t>> dp(N + 1, vector<int64_t>(M + 1, LLONG_MIN));
	dp[0][0] = 0;
	for (int i = 0; i <= N; ++i)
		for (int j = 0; j <= M; ++j) {
			if (i > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j] + P[i] * (preA[i] + preB[j] <= S[i]));
			if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1] + Q[j] * (preA[i] + preB[j] <= T[j]));
			ans = max(ans, dp[i][j]);
		}

	cout << ans << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 10056 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 10056 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 10056 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -