Submission
Status:
PPPPPPPPPP
Score: 100
User: Nathlol2
Problemset: ความลึก
Language: cpp
Time: 0.589 second
Submitted On: 2025-05-06 11:18:46
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(false);
int n, q;
cin >> n >> q;
int cur = 0;
vector<int> ll(n), len(n, -1);
int s = 0, mx = -1;
for(int i = 0;i<n;i++){
int d, l;
cin >> d >> l;
cur += d;
if(d == 1){
ll[cur] = s;
s += l;
len[cur] = max(len[cur], s - ll[cur]);
}else{
s += l;
len[cur] = max(len[cur], s - ll[cur]);
}
mx = max(mx, cur);
}
while(q--){
int x;
cin >> x;
int ans = 0;
for(int j = mx;j>0;j--){
if(x <= len[j]){
ans = j;
break;
}
}
cout << ans << '\n';
}
}