This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll dp[1001][1001];
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<1001;i++)
{
for(int j=0;j<1001;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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |