Submission #596031

#TimeUsernameProblemLanguageResultExecution timeMemory
596031HanksburgerCloud Computing (CEOI18_clo)C++17
100 / 100
581 ms2008 KiB
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> a[4005]; long long dp[100005], tmp[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n; for (int i=1; i<=n; i++) { cin >> a[i].first.second >> a[i].first.first >> a[i].second; a[i].second*=-1; } cin >> m; for (int i=n+1; i<=n+m; i++) { cin >> a[i].first.second >> a[i].first.first >> a[i].second; a[i].first.second*=-1; } sort(a+1, a+n+m+1, greater<pair<pair<int, int>, int> >()); for (int i=1; i<=1e5; i++) dp[i]=-1e18; for (int i=1; i<=n+m; i++) { for (int j=0; j<=1e5; j++) { if (j-a[i].first.second>=0 && j-a[i].first.second<=1e5) tmp[j]=max(dp[j], dp[j-a[i].first.second]+a[i].second); else tmp[j]=dp[j]; } // cout << "i=" << i << ": " << a[i].second << ' ' << a[i].first.first << ' ' << a[i].first.second << '\n'; for (int j=0; j<=1e5; j++) { dp[j]=tmp[j]; // if (j<=15) // cout << dp[j] << ' '; } // cout << '\n'; } long long ans=0; for (int i=0; i<=1e5; i++) ans=max(ans, dp[i]); cout << ans; 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...