ABC141C Attack Survival
Problem summary
You have an integer vector v whose length is N and whose initial element is K.
Now we have Q queries for updating v.
In query q_i (), you give an integer A_i and should decrement all other elements without A_i-th element of v (1-indexed).
After executing Q queries, determine whether each elements are larger than 0 or not and print the result.
Constraints
・Time Limit: 2sec
・Memory Limit: 1024MB
・All values in input are integers
・
・
・
・
Answer
blute-force
We simulate each queries in a row.
this takes O(N) per query so entire solution is O(NQ).
optimized
The answer is not depend on the order of queries so we can think only how many times i-th element of v is decremented ().
the result of i-th element of v is (k - q + cnt[i] > 0 ? "Yes" : "No")
This takes O(N + Q) and It's satisfy the time limit.