Mortgage

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

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 nn months of his life, he will earn the income a_ia\_i that can be spent on the mortgage (other costs have already been accounted for, hence a_ia\_i 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 xx units of money over the course of kk months, starting in month ii, and ending in month i+k1i+k-1. Each of these months, he needs to be able to pay xx units of money. If he has any leftover income in month ii, i.e. a_i>xa\_i > x, he can save the rest and use it towards some of the future payments (same for any leftover money in months i+1i+1 to i+k1i+k-1). However, he cannot count on saving any money prior to month ii, 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 nn months and a list of mm different time intervals. The ii-th time interval is defined by two numbers, s_is\_i, and k_ik\_i. The mortgage loan starts on the month s_is\_i and lasts for k_ik\_i months, i.e. the last payment is done on the month s_i+k_i1s\_i+k\_i-1. For each of the time intervals, determine what the largest monthly payment that Andrej can afford is.

입력

The first line contains two integers, nn and mm, the number of months, and the number of different time intervals, respectively. The second line contains nn space-separated integers, a_1,,a_na\_1, \ldots, a\_n, Andrej's income over the next nn months. This is followed by mm lines describing different time intervals, each line containing two space-separated integers s_is\_i and k_ik\_i.

출력

Print out mm lines, one for each time interval. Print out the largest integer amount of monthly payment that Andrej can afford to pay for the ii-th mortgage. If the number is strictly smaller than 0, print "stay with parents" (without quotation marks).

제한

  • 1n,m21051 \leq n,m \leq 2\cdot 10^5
  • 109a_i109-10^9 \leq a\_i \leq 10^9
  • 1s_in;i1 \leq s\_i \leq n; \forall i
  • 1k_i1 \leq k\_i and s_i+k_i1n;is\_i+k\_i-1 \leq n; \forall i

힌트

For the first interval, a monthly payment of 44 units is the largest Andrej can afford. For a monthly payment of 55, he would run out of money for his final payment. Negative income on month 6 means that Andrej cannot afford any mortgage for interval 4, regardless of its size.