Submission

Status:
PPPPPPPPPP

Score: 100

User: Winzzwz

Problemset: เข้าแถว

Language: cpp

Time: 0.012 second

Submitted On: 2025-03-05 14:06:09

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n,l,t[100100],dp[100100];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> l;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
        dp[i] = max(dp[i-1],t[i]);
        // cout << i << " : " << dp[i] << "\n";
    }
    while (l--) {
        int nn; cin >> nn;
        if (dp[nn-1] < t[nn]) cout << 0 << "\n";
        else cout << dp[nn-1]-t[nn]+1 << "\n";
    }



    return 0;
}