Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: anonymous
Problemset: ความลึก
Language: cpp
Time: 0.437 second
Submitted On: 2026-11-08 18:02:40
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,q,max_depth = 0; cin >> n >> q;
int d,l,ship[q],depth = 0, sum =0, left[n], maxl[n] = {0};
left[0] = 0;
for(int i=0;i<n;i++){
cin >> d >> l;
depth += d;
if(d == 1){
left[depth] = sum;
sum += l;
maxl[depth] = max(maxl[depth],sum - left[depth]);
}
if(d == -1){
sum += l;
maxl[depth] = max(maxl[depth],sum-left[depth]);
}
max_depth = max(depth, max_depth);
}
for(int i=0;i<q;i++) cin >> ship[i];
for(int i=0;i<q;i++){
int ans =0;
for(int j=max_depth ; j > 0;j--){
if(ship[i] <= maxl[j]){
ans = j;
break;
}
}
cout << ans << '\n';
}
}