Submission #1040344

#TimeUsernameProblemLanguageResultExecution timeMemory
1040344vjudge1Divide and conquer (IZhO14_divide)C++14
17 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N=5e3+5; int n; int x[N], g[N], e[N]; int dp[N], fe[N], fg[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i=1; i<=n; i++) cin >> x[i] >> g[i] >> e[i]; for(int i=1; i<=n; i++) { fg[i]=fg[i-1]+g[i]; fe[i]=fe[i-1]+e[i]; } for(int i=1; i<=n; i++) dp[i]=g[i]; for(int i=1; i<=n; i++) for(int j=1; j<i; j++) { int req=(x[i]-x[j]); int have=(fe[i]-fe[j-1]); if(have>=req) dp[i]=max(dp[i], dp[j]+(fg[i]-fg[j])); } cout << *max_element(dp+1, dp+1+n); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...