#TP0000055. Những con kiến ma (Ghost Ants)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những con kiến ma (Ghost Ants)
Ghost Ants
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are ants, numbered through , on a number line. Ant initially stands at integer coordinate , and all initial coordinates are distinct. Binary string of length specifies their directions: means left, while means right.
From time , each ant moves at constant speed in its chosen direction until time . When ants meet, they pass through one another without changing direction or speed. They then stop at that ending time.
Count the pairs of different ants that have met between time and time , counting each pair once.
Input
- The first line contains integers : the number of ants and the time parameter.
- The second line contains a binary string of exactly characters, encoding directions.
- The third line contains exactly integers , the initial positions in ant-number order.
Output
Print one integer: the number of ant pairs meeting within the specified time.
Subtasks
- Subtask 1 (20 points): ; ; ; for every ; all are pairwise distinct.
- Subtask 2 (30 points): ; ; ; for every ; all are pairwise distinct.
- Subtask 3 (50 points): ; ; ; for every ; all are pairwise distinct.
Examples
Input
6 3
101010
-5 -1 0 1 2 4
Output
5
Explanation
Exactly five ant pairs meet: at time , at , at , at , and at . All occur no later than time , giving answer .