### PROBLEM LINK:

**Author and Editorialist:** Hussain Kara Fallah

**Tester:** Michael Nematollahi

### PREREQUISITES:

NONE

### PROBLEM:

In the next month you are gonna solve problems. The month consists of 31 days. You know for each day how many problems you will be solving at. You are given D pairs of the form (day_i,prob_i) denoting that you will solve prob_i problems at the {day_i}^{th} day of the month.

You are given then Q Queries of the form (dead_i,req_i). For each query you have a deadline dead_i which presents the last day that you could be solving problem at (the day itself is included). You need to tell if you will solve at least req_i problems up to that day (answer is Yes/No).

### EXPLANATION:

This problem is a straightforward translation of the words written in the statement. Due to low constraints, we can manage to keep the pairs of problem-solving events (day_i,prob_i) in a vector/array.

Afterward, for each query, we can iterate through all the problem-solving events. If the day corresponding to some event is the deadline day (or someday before) we can assume that we are gonna solve the number of problems planned for that day. We sum up all the problems amounts of these days.

If our total sum is less than the required, we report that we cannot satisfy. Otherwise, we are fine.

Check the authorâ€™s code for the implementation of this approach. It runs in O(Q*D).

The testerâ€™s approach is a bit faster (but not needed for such constraints). We maintain an array tot[1..31] recording how many problems we will solve each day.

Letâ€™s run the following pseudo-code:

```
for(i from 1 to 31)
tot[i] += tot[i-1]
```

Thus we will have in tot_i the total number of problems we will solve from the first day till the i_{th} day (included). Now our query (dead_i,prob_i) can be answered faster.

We can simply check if(req_i<= tot[dead_i]) and output the answer accordingly. Check the testerâ€™s implementation for details. This implementation runs in O(Q)