Submission #701299

#TimeUsernameProblemLanguageResultExecution timeMemory
701299NourWaelArt Exhibition (JOI18_art)C++14
50 / 100
745 ms262144 KiB
#include <iostream> #include <bits/stdc++.h> typedef long long ll; using namespace std; ll dp[5001][5001]; int n; vector<pair<ll,ll>>v; ll joi(int i , int last) { if(i==n) return 0; ll m=0; int j=i; if(last==-1) { m=joi(i+1,j)+v[i].second; } else { if(dp[i][last]!=-1e17) return dp[i][last]; else m=joi(i+1,i)+v[i].second-(v[i].first-v[last].first); } m=max(m,joi(i+1,last)); if(last!=-1) dp[i][last]=m; return m; } int main() { cin>>n; v.resize(n); for(int i=0;i<5001;i++) { for(int j=0;j<5001;j++) { dp[i][j]=-1e17; } } for(int i=0;i<n;i++) { cin>>v[i].first>>v[i].second; } sort(v.begin(),v.end()); cout<<joi(0,-1); 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...