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 <vector>
#include <cmath>
#include <iomanip>
using namespace std;
const int N=1001;
double dp[N][N];
double dp1[N][N];
int main()
{
cout<<fixed<<setprecision(4);
int n;
cin>>n;
vector<double> a,b;
for(int i=0;i<n;i++)
{
double x,y;
cin>>x>>y;
a.push_back(x);
b.push_back(y);
}
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
dp[i][j]=dp1[i][j]=-1e9;
dp[0][0]=dp1[0][0]=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+a[i]-1);
dp1[i+1][j]=max(dp1[i+1][j],dp1[i][j]);
dp1[i+1][j+1]=max(dp1[i+1][j+1],dp1[i][j]+b[i]-1);
}
}
double ans=0;
for(int j=0;j<=n;j++)
for(int i=0;i<=n;i++)
ans=max(ans,min(dp[n][j]-i,dp1[n][i]-j));
cout<<ans<<endl;
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... |