#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {for(auto e:x) cerr<<e<<",";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
int n,l;
vector<pii> a;
int distpos(int i,int j) {
int d1=a[i].second,d2=a[j].second;
return min(abs(d2-d1),l-max(d2,d1)+min(d2,d1));
}
int dist(int d1,int d2) {
return min(abs(d2-d1),l-max(d2,d1)+min(d2,d1));
}
int solve(int cur,bool select,int tt,int cnt,int pos,vector<int> path) {
//debug(cur,select,tt,cnt,pos);
//if(cnt==5) debug(path);
if(tt>a[cur].first) return 0;
if(cur==n-1) {
return cnt;
}
int res=0;
res=max(res,solve(cur+1,0,tt,cnt,pos,path));
path.push_back(cur+1);
if(tt+dist(pos,a[cur+1].second)<=a[cur+1].first) {
//debug(pos,a[cur+1].second,dist(pos,a[cur+1].second));
res=max(res,solve(cur+1,1,tt+dist(pos,a[cur+1].second),cnt+1,a[cur+1].second,path));
}
return res;
}
int main () {
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>l; a.resize(n);
for(int i=0;i<n;i++) cin>>a[i].second;
for(int i=0;i<n;i++) cin>>a[i].first;
sort(all(a));
// cout<<"=="<<endl;
// for(int i=0;i<n;i++) cout<<a[i].first<<' '<<a[i].second<<endl;
// cout<<"=="<<endl;
vector<int> temp,temp2; temp2.push_back(0);
if(n<=15) {
cout<<max(solve(0,0,0,0,0,temp),solve(0,1,dist(0,a[0].second),1,a[0].second,temp2))<<endl; return 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |