Submission #860769

#TimeUsernameProblemLanguageResultExecution timeMemory
860769browntoadTwo Dishes (JOI19_dishes)C++14
10 / 100
134 ms31884 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define pii pair<int, int> #define ppi pair<pii, int> #define pip pair<int, pii> #define pb push_back #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, n+1) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define SZ(x) (int)((x).size()) const ll maxn = 2005; const ll inf = (1ll<<60); const ll mod = 1e9+7; int n, m; int dp[maxn][maxn]; signed main(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin>>n>>m; vector<int> a(n+1), s(n+1), p(n+1); vector<int> b(m+1), t(m+1), q(m+1); REP1(i, n) cin>>a[i]>>s[i]>>p[i]; REP1(j, m) cin>>b[j]>>t[j]>>q[j]; REP1(i, n) a[i] += a[i-1]; REP1(j, m) b[j] += b[j-1]; if (n > 2000 || m > 2000){ REP1(i, n) p[i] += p[i-1]; REP1(j, m) q[j] += q[j-1]; int k = s[1]; int mx = -inf; int tot = 0; REP(i, n+1){ if (a[i] <= k) tot = p[i]; int id = upper_bound(ALL(b), k-a[i]) - b.begin(); id = max(0ll, id-1); mx = max(mx, q[id] + tot); } tot = 0; REP(i, n+1){ if (b[i] <= k) tot = q[i]; int id = upper_bound(ALL(a), k-b[i]) - a.begin(); id = max(0ll, id-1); mx = max(mx, p[id] + tot); } cout<<mx<<endl; return 0; } REP(i, n+1){ REP(j, m+1){ if (i > 0) dp[i][j] = max(dp[i][j], dp[i-1][j] + (a[i]+b[j] <= s[i])); if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j-1] + (a[i]+b[j] <= t[j])); } } cout<<dp[n][m]<<endl; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...