Submission #471285

#TimeUsernameProblemLanguageResultExecution timeMemory
471285IvnFArt Exhibition (JOI18_art)C++14
50 / 100
295 ms202372 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ull unsigned long long #define fi first #define se second #define ld long double ll n, dp[5005][5005], pref[5005]; pair<ll, ll>arr[5005]; ll solve(ll l, ll r){ if(l > r) return 0; if(dp[l][r]!=-1) return dp[l][r]; ll sums=(pref[r]-pref[l-1])-(arr[r].fi-arr[l].fi); ll ans=sums; ans=max(ans, solve(l+1, r)); ans=max(ans, solve(l, r-1)); return dp[l][r]=ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; memset(dp, -1, sizeof dp); for(int i=1;i<=n;++i){ cin >> arr[i].fi >> arr[i].se; } sort(arr+1, arr+1+n); for(int i=1;i<=n;++i) pref[i]=pref[i-1]+arr[i].se; cout << solve(1, n) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...