codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1742E.md (2536B)


      1 Source: https://codeforces.com/problemset/problem/1742/E
      2 
      3 E. Scuza
      4 
      5 time limit per test
      6 
      7 3 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Timur has a stairway with $n$ steps. The $i$-th step is $a_i$ meters higher than its predecessor. The first step is $a_1$ meters higher than the ground, and the ground starts at $0$ meters.
     22 
     23  ![](https://espresso.codeforces.com/397398c944e94083d796d12d70475f10a0f0e26c.png) The stairs for the first test case. 
     24 
     25 Timur has $q$ questions, each denoted by an integer $k_1, \dots, k_q$. For each question $k_i$, you have to print the maximum possible height Timur can achieve by climbing the steps if his legs are of length $k_i$. Timur can only climb the $j$-th step if his legs are of length at least $a_j$. In other words, $k_i \geq a_j$ for each step $j$ climbed.
     26 
     27 Note that you should answer each question independently.
     28 
     29 Input
     30 
     31 The first line contains a single integer $t$ ($1 \leq t \leq 100$) — the number of test cases.
     32 
     33 The first line of each test case contains two integers $n, q$ ($1 \leq n, q \leq 2\cdot10^5$) — the number of steps and the number of questions, respectively.
     34 
     35 The second line of each test case contains $n$ integers ($1 \leq a_i \leq 10^9$) — the height of the steps.
     36 
     37 The third line of each test case contains $q$ integers ($0 \leq k_i \leq 10^9$) — the numbers for each question.
     38 
     39 It is guaranteed that the sum of $n$ does not exceed $2\cdot10^5$, and the sum of $q$ does not exceed $2\cdot10^5$.
     40 
     41 Output
     42 
     43 For each test case, output a single line containing $q$ integers, the answer for each question.
     44 
     45 Please note, that the answer for some questions won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 3
     53 
     54 4 5
     55 
     56 1 2 1 5
     57 
     58 1 2 4 9 10
     59 
     60 2 2
     61 
     62 1 1
     63 
     64 0 1
     65 
     66 3 1
     67 
     68 1000000000 1000000000 1000000000
     69 
     70 1000000000
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 1 4 4 9 9 
     77 0 2 
     78 3000000000
     79 ```
     80 
     81 Note
     82 
     83 Consider the first test case, pictured in the statement.
     84 
     85 * If Timur's legs have length $1$, then he can only climb stair $1$, so the highest he can reach is $1$ meter.
     86 * If Timur's legs have length $2$ or $4$, then he can only climb stairs $1$, $2$, and $3$, so the highest he can reach is $1+2+1=4$ meters.
     87 * If Timur's legs have length $9$ or $10$, then he can climb the whole staircase, so the highest he can reach is $1+2+1+5=9$ meters.
     88 
     89 In the first question of the second test case, Timur has no legs, so he cannot go up even a single step. :(