#P13814. [CERC 2022] Mortgage
[CERC 2022] Mortgage
题目描述
Andrej is a typical modern student, dreaming to buy a house one day. Since buying real property is no piece of cake, he is planning out his life and trying to figure out exactly how and when he will be able to afford one. To buy a house, he aims to take a mortgage loan that will then need to be paid back in multiple payments over the course of several months. For each of the next months of his life, he will earn the income that can be spent on the mortgage (other costs have already been accounted for, hence can be negative). He is now looking at a list of various properties and mortgage loans and is trying to figure out which of them he can afford.
Suppose that he takes a mortgage that involves paying units of money over the course of months, starting in month , and ending in month . Each of these months, he needs to be able to pay units of money. If he has any leftover income in month , i.e. , he can save the rest and use it towards some of the future payments (same for any leftover money in months to ). However, he cannot count on saving any money prior to month , regardless of the income in those months. He will spend it all on his current rent and avocado toast.
You are given the list of Andrej's income for the next months and a list of different time intervals. The -th time interval is defined by two numbers, , and . The mortgage loan starts on the month and lasts for months, i.e. the last payment is done on the month . For each of the time intervals, determine what the largest monthly payment that Andrej can afford is.
输入格式
The first line contains two integers, and , the number of months, and the number of different time intervals, respectively. The second line contains space-separated integers, , Andrej's income over the next months. This is followed by lines describing different time intervals, each line containing two space-separated integers and .
输出格式
Print out lines, one for each time interval. Print out the largest integer amount of monthly payment that Andrej can afford to pay for the -th mortgage. If the number is strictly smaller than 0, print "stay with parents" (without quotation marks).
9 5
6 1 10 9 5 -2 3 1 -1
3 6
1 4
3 3
6 1
8 2
4
3
8
stay with parents
0
提示
Comment
For the first interval, a monthly payment of units is the largest Andrej can afford. For a monthly payment of , he would run out of money for his final payment. Negative income on month means that Andrej cannot afford any mortgage for interval , regardless of its size.
Input limits
- and