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 <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=3e3+5, kx=20;
ll n, a[nx], b[nx], ans, d[nx], dp[2][kx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i]>>b[i], d[i]=d[i-1]+a[i]-b[i];
for (int i=1; i<=n; i++)
{
int c=i%2, p=1-c;
dp[c][0]=dp[p][0]+abs(d[i]);
for (int j=1; j<=d[n]; j++) dp[c][j]=min(dp[c][j-1], dp[p][j]+abs(j-d[i])); //printf("%d %d %d\n", i, j, dp[c][j]);
}
cout<<dp[n%2][d[n]];
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |