This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
/// fin(task),fou(task);
//#endif
NHP
//modwwe
// cin>>res;
ngha(),down
checktime
}
int a[301];
int b[301];
int dp[207][207][207][2];
void ngha()
{
cin>>n>>k;
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=n; i++)
cin>>b[i];
///n+1 la deo dung
for(int i=0; i<=n; i++)
for(int j=n+1; j>i; --j)
for(int z=0; z<=n; z++)
dp[i][j][z][0]=dp[i][j][z][1]=1e18;
dp[0][n+1][0][1]=0;
dp[0][n+1][0][0]=0;
a[n+1]=k;
for(int i=0; i<=n; i++)
for(int j=n+1; j>i; --j)
for(int z=0; z<=i+n+1-j; z++)
{
dp[i][j][z][1]=min(dp[i][j][z][0]+a[i]+k-a[j],dp[i][j][z][1]);
dp[i][j][z][0]=min(dp[i][j][z][0],dp[i][j][z][1]+a[i]+k-a[j]);
if(i!=n&&i+1<j)
{
if(dp[i][j][z][1]+a[i+1]-a[i]<=b[i+1])
dp[i+1][j][z+1][1]=min(dp[i+1][j][z+1][1],dp[i][j][z][1]+a[i+1]-a[i]);
else
dp[i+1][j][z][1]=min(dp[i+1][j][z][1],dp[i][j][z][1]+a[i+1]-a[i]);
}
if(j-1>i)
{
if(dp[i][j][z][0]+a[j]-a[j-1]<=b[j-1])
dp[i][j-1][z+1][0]=min(dp[i][j-1][z+1][0],dp[i][j][z][0]+a[j]-a[j-1]);
else
dp[i][j-1][z][0]=min(dp[i][j-1][z][0],dp[i][j][z][0]+a[j]-a[j-1]);
}
}
s2=0;
for(int i=0; i<=n; i++)
for(int z=0; z<=n; z++)
if(min(dp[i][i+1][z][0],dp[i][i+1][z][0])!=1e18)
{
s2=max(s2,z);
}
cout<<s2;
}
Compilation message (stderr)
ho_t3.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
# | 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... |