제출 #938490

#제출 시각아이디문제언어결과실행 시간메모리
938490danikoynovTwo Dishes (JOI19_dishes)C++14
10 / 100
8761 ms105268 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 2e5 + 10; int n, m; ll a[maxn], s[maxn], p[maxn]; ll b[maxn], t[maxn], q[maxn]; ll pref[2][maxn]; void input() { cin >> n >> m; for (int i = 1; i <= n; i ++) cin >> a[i] >> s[i] >> p[i]; for (int i = 1; i <= m; i ++) cin >> b[i] >> t[i] >> q[i]; } void prefix_sums() { for (int i = 1; i <= n; i ++) { pref[0][i] = pref[0][i - 1] + a[i]; } for (int i = 1; i <= m; i ++) { pref[1][i] = pref[1][i - 1] + b[i]; } } ll dp[2010][2010]; int con[maxn]; const ll inf = 1e18; void dynamic() { for (int i = 0; i <= n; i ++) { ll free_time = s[i] - pref[0][i]; while(con[i] <= m && pref[1][con[i]] <= free_time) con[i] ++; con[i] --; } 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] + (pref[0][i] + pref[1][j] <= s[i])); } if (j > 0) { dp[i][j] = max(dp[i][j], dp[i][j - 1] + (pref[0][i] + pref[1][j] <= t[j])); } ///cout << "state " << i << " " << j << " " << dp[i][j] << endl; } } cout << dp[n][m] << endl; } void solve() { input(); prefix_sums(); dynamic(); } int main() { speed(); solve(); 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...