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>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
#define LOCALIO "C:/Users/admin/Documents/Code/"
ll n, L;
ll a[205], t[205];
ll p[205], used[205], ans;
ll dis(ll a, ll b)
{
ll Max=max(a, b), Min=min(a, b);
return min(Max-Min, Min-Max+L);
}
void show()
{
ll res=0, crr=0, pos=0;
for (ll i=1; i<=n; i++)
crr+=dis(pos, a[p[i]]), pos=a[p[i]], res+=crr<=t[p[i]];
ans=max(ans, res);
}
void backtrack(ll i)
{
if (i==n+1)
{
show();
return;
}
for (ll j=1; j<=n; j++)
if (!used[j])
{
used[j]=1; p[i]=j;
backtrack(i+1);
used[j]=0;
}
}
int main()
{
#ifdef LOCAL
freopen( LOCALIO "input.txt","r",stdin) ;
freopen( LOCALIO "output.txt","w",stdout) ;
#endif
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
// freopen("FIBONACCI.inp","r",stdin);
// freopen("FIBONACCI.out","w",stdout);
cin >> n >> L;
for (ll i=1; i<=n; i++)
cin >> a[i];
for (ll i=1; i<=n; i++)
cin >> t[i];
backtrack(1);
cout << ans;
}
# | 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... |