report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
The k-th candy - MarisaOJ: Marisa Online Judge

The k-th candy

Time limit: 1000 ms
Memory limit: 256 MB
There are $n$ candy types. There are $a_i$ candies of type $i$ and they weigh $w_i$ each. No 2 types of candy have the same weight. All the candies are poured onto a table and arranged in a row so that their weight form a non-decreasing list. You are given $q$ queries, how heavy is the $k^{th}$ candy on the table? ### Input - The first line contains 3 integers $n, q$. - Next $n$ lines, each line contains 2 integers $a_i, w_i$. - Next $q$ lines, each line contains a single integer $k$, a query. ### Output - Print $q$ lines, $i^{th}$ is the answer for query $i$. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le a_i, w_i \le 10^9$. - $1 \le k \le a_1 + a_2 + ... + a_n \le 10^{14}$. ### Example Input: ``` 3 3 2 2 1 1 3 3 1 3 5 ``` Output: ``` 1 2 3 ```
Introduction to Binary Search
Binary search
Binary search 2
Binary search 3
Large subarray
Count query
Counting pairs
The k-th candy
Triangle edges
Hamming number
Consecutive integers
Gnimmah distance
Subarray
Topic
Sorting
Binary search
Rating 800
Solution (3) Solution