Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: dddrrrr
Problemset: เข้าแถว
Language: cpp
Time: 0.007 second
Submitted On: 2025-10-16 17:53:34
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n ,m;
cin >> n >> m;
vector <int> vec(n) ,height(n);
for(int i=0 ;i<n ;i++)cin >> vec[i];
height[0] = vec[0];
for(int i=1 ;i<n ;i++){
height[i] = max(vec[i] ,height[i-1]);
}
while(m--){
int x;
cin >> x;
x--;
if(height[x] < vec[x] || height[x] == vec[x])cout << 0 << "\n";
else cout << height[x] - vec[x] +1 << '\n';
}
return 0;
}