Submission #708726

#TimeUsernameProblemLanguageResultExecution timeMemory
708726PixelCatTwo Dishes (JOI19_dishes)C++14
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> #define For(i, a, b) for(int i = a; i <= b; i++) #define Forr(i, a, b) for(int i = a; i >= b; i--) #define F first #define S second #define sz(x) ((int)x.size()) #define all(x) x.begin(), x.end() #define eb emplace_back #define int LL using namespace std; using LL = long long; using pii = pair<int, int>; // const int MAXN = 1000010; const int MAXN = 2010; int a1[MAXN]; int s1[MAXN]; int p1[MAXN]; int pr1[MAXN]; int t1[MAXN]; int a2[MAXN]; int s2[MAXN]; int p2[MAXN]; int pr2[MAXN]; int t2[MAXN]; int su[MAXN][MAXN]; int dp[MAXN]; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // NYA =^-w-^= int n, m; cin >> n >> m; assert(n <= MAXN); For(i, 1, n) { cin >> a1[i] >> s1[i] >> p1[i]; pr1[i] = pr1[i - 1] + a1[i]; } For(i, 1, m) { cin >> a2[i] >> s2[i] >> p2[i]; pr2[i] = pr2[i - 1] + a2[i]; } For(i, 1, n) { auto it = upper_bound(pr2, pr2 + m + 1, s1[i] - pr1[i]); t1[i] = it - pr2 - 1; // cout << i << " " << t1[i] << "\n"; // dp[i][0] = dp[i - 1][0] + (t1[i] >= 0); } For(i, 1, m) { auto it = upper_bound(pr1, pr1 + n + 1, s2[i] - pr2[i]); t2[i] = it - pr1 - 1; // cout << i << " " << t2[i] << "\n"; // dp[0][i] = dp[0][i - 1] + (t2[i] >= 0); For(j, 0, t2[i]) { su[j][i]++; } } // For(i, 1, n) For(j, 1, m) { // dp[i][j] = max(dp[i - 1][j] + (j <= t1[i]), dp[i][j - 1] + (i <= t2[j])); // } // cout << dp[n][m] << "\n"; For(i, 0, n) For(j, 1, m) su[i][j] += su[i][j - 1]; int ans = 0; For(i, 1, n) if(t1[i] >= 0) { int add = 0; dp[i] = su[0][t1[i]] + 1; Forr(i2, i - 1, 1) { if(t1[i2] > t1[i]) add++; else { dp[i] = max(dp[i], dp[i2] + su[i2][t1[i]] - su[i2][t1[i2]] + add + 1); } } // cout << i << " " << dp[i] << "\n"; ans = max(ans, dp[i] + su[i][m] - su[i][t1[i]]); } cout << ans << "\n"; return 0; }
#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...