錯在第一個側資
#include<bits/stdc++.h>// 95%
#define int long long
using namespace std;
struct node{
int l,r,v;
};
node arr[100009]; //left,right,value
int road[100009];
int ans = 0;
int maxi = 0;
queue<int>q;
//-----------------------
int32_t main(){
int n,m;cin>>n>>m;
for(int i = 1;i<=n;i++){
cin>>road[i];
}
arr[0].r = 1;
arr[n+1].l = n-1;
for(int i = 1;i<=n;i++){
cin>>arr[i].v;
arr[i].l = i-1;
arr[i].r = i+1;
q.push(i);
}
road[n+1] = m;
road[0] = 0;
//-------------------------------
while(!q.empty()){
int x = q.front();q.pop();
if(arr[x].v==0)continue;
if(road[x]-road[arr[x].l]>=arr[x].v||road[arr[x].r]-road[x]>=arr[x].v){
q.push(arr[x].l);
q.push(arr[x].r);
arr[arr[x].l].r = arr[x].r;
arr[arr[x].r].l = arr[x].l;
ans+=1;
maxi = max(maxi,arr[x].v);
arr[x].v = 0;
//arr[x] -> died
//cout<<x<<" ";
}
}
//-------------------------------
cout<<ans<<"\n"<<maxi;
}
if(arr[x].v==0)continue;
似乎是因為題目輸入的高度可能是0,所以這裡的判斷會有問題
可是輸入說明不是說正整數嗎...