D. Nastya Is Buying Lunch

Quiz

https://codeforces.com/contest/1136/problem/D

AC Code

https://codeforces.com/contest/1136/submission/56483886

参考

https://cinnamo-coder.hatenablog.com/entry/2019/03/12/033934

ポイント

  • 一番後ろ(私)が前の列の人を追い抜くのではなく、前にいる人が私の後ろまで来れるか?と考える

Note (Sample 3)

input
5 2
3 1 5 4 2
5 2
5 4
output
1

f:id:peroon:20190704023345j:plain