Submission #630427

#TimeUsernameProblemLanguageResultExecution timeMemory
630427KarliverCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
311 ms133920 KiB
	
#include <bits/stdc++.h>

#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()
#define ff first
#define se second
#define mp make_pair
using ll = long long;
int mod = (ll)1e9 + 7;
const int INF = 1e9 + 1;
const int N = 210;
const double eps = 1e-7;
const  long  long inf = 1e18;
template <class T> using V = vector<T>;  
template <class T> using VV = V<V<T>>;  
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
    return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
    return (x > y ? x = y, 1 : 0);
}



void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)


int n, L, a[N], d[N];

long long dis, dp[N][N][N][2];
void solve() {	
	
	cin >> n >> L;
	for(int i = 1;i <= n;++i)
		cin >> a[i];
	
	for(int i = 1;i <= n;++i)
		cin >> d[i];
	++n;
	forn(k, n) forn(len, n) forn(i, n) forn(t, 2) dp[i][len][k][t] = inf;
	dp[0][0][0][0] = 0;
	int ans = 0;
	for(int k = 0;k < n;++k) {
		for(int len = 0;len < n;++len) {
			for(int i = 0;i < n;++i) {
				for(int t = 0;t < 2;++t) {
					if(dp[i][len][k][t] == inf)continue;
					//debug(i, len, k, t);
					int cur = (t == 0 ? i : (i + len) % n);
					int lf = (i + n - 1) % n;
					int rf = (i + len + 1) % n;
					dis = min(L-abs(a[cur]-a[lf]), abs(a[cur]-a[lf])) + dp[i][len][k][t];
					ckmi(dp[lf][len+1][k+(dis<=d[lf])][0], dis);
					dis = min(L-abs(a[cur]-a[rf]), abs(a[cur]-a[rf])) + dp[i][len][k][t];
					ckmi(dp[i][len+1][k+(dis<=d[rf])][1], dis);
					ckma(ans, k);
					//debug(k);
				}
			}
		}
	}
	
	cout << ans << '\n';
	
}
void test_case() {
    int t;
    cin >> t;
    forn(p, t) {

        //cout << "Case #" << p + 1 << ": ";
        solve();
    }
}
int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}
         
    
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...