제출 #578921

#제출 시각아이디문제언어결과실행 시간메모리
578921mousebeaverTwo Dishes (JOI19_dishes)C++14
0 / 100
153 ms15904 KiB
#define ll long long #define ull unsigned ll #define pli pair<ll, int> #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin>>n>>m; vector<ll> a(n); vector<ll> s(n); vector<ll> p(n); for(int i = 0; i < n; i++) { cin>>a[i]>>s[i]>>p[i]; } vector<ll> b(m); vector<ll> t(m); vector<ll> q(m); for(int i = 0; i < m; i++) { cin>>b[i]>>t[i]>>q[i]; } vector<ll> prea(n); prea[0] = a[0]; for(int i = 1; i < n; i++) { prea[i] = prea[i-1]+a[i]; } vector<ll> preb(m); preb[0] = b[0]; for(int i = 1; i < m; i++) { preb[i] = preb[i-1]+b[i]; } vector<ll> prep(n); prep[0] = p[0]; for(int i = 1; i < n; i++) { prep[i] = prep[i-1]+p[i]; } vector<ll> preq(n); preq[0] = q[0]; for(int i = 1; i < n; i++) { preq[i] = preq[i-1]+q[i]; } ll time = s[0]; int qindex = m-1; while(qindex >= 0 && preb[qindex] > time) { qindex--; } ll output = 0; if(qindex >= 0) { output = max(output, preq[qindex]); } for(int i = 0; i < n && prea[i] <= time; i++) { while(qindex >= 0 && preb[qindex]+prea[i] > time) { qindex--; } if(qindex > 0) { output = max(output, prep[i]); } else { output = max(output, prep[i]+preq[qindex]); } } cout<<output<<"\n"; /*vector<vector<ll>> dp(n+1, vector<ll> (m+1, 0)); for(int i = 0; i <= n; i++) { for(int j = 0; j <= m; j++) { ll time = 0; if(i > 0) { time += prea[i-1]; } if(j > 0) { time += preb[j-1]; } //Dish 1: if(i > 0) { ll score = dp[i-1][j]; if(time <= s[i-1]) { score += p[i-1]; } dp[i][j] = max(dp[i][j], score); } if(j > 0) { ll score = dp[i][j-1]; if(time <= t[j-1]) { score += q[j-1]; } dp[i][j] = max(dp[i][j], score); } } } cout<<dp[n][m]<<"\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...