Good Evening sweetheart!![Medium]
Practice
4 (5 votes)
Medium
Problem
76% Success 561 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Scube sold you N candles, for each candle i you know its height H[i]​. ​Using a candle during one evening decreases the candle height by 1. You plan to have at most M romantic evenings. For each evening i you know the number of candles C[i] you want to lit. Find a strategy of lighting the candles in order to maximize the number of evenings you can spend. You are forced to stop after the the night i when you can't light C[i] candles.
Standard input
The first line contains two integers N and M.
The second line contains N integers representing the initial heights of the candles.
The third line contains M integers representing the number of candles you want to lit each evening.
Standard output
Print a single integer representing the maximum number of evening you can spend, satisfying the candle requirements.
Constraints and notes
1≤N,M≤10^5
1<=H[i]<=10^5
1 <=C[i]<=10^5
​​

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
27 votes
Tags:
Advanced Data StructuresAlgorithmsData StructuresDynamic ProgrammingFenwick TreeSegment Trees
Points:30
25 votes
Tags:
Advanced Data StructuresData StructuresSegment Trees
Points:30
9 votes
Tags:
Advanced Data StructuresData StructuresGCDImplementationNumber theorySegment Trees