Question: Please give me a code in C . In the Warzone game, a mission period will continue for n days. During this time, the player

Please give me a code in C. In the Warzone game, a mission period will continue for n days. During this time, the
player needs to complete missions in m different areas. The areas are numbered from 1
to m.
Each day, the player can complete a mission for one of the m areas. However, some
days might not have any missions available for completion. The player is not allowed to
complete more than one mission in a single day.
For each day, information is given about which areas mission can be completed on that
day. On days without available missions, the player can either prepare for missions (it
takes the whole day) or rest.
For each area, the player knows the number of preparation days required to complete a
mission in that area. The player can switch between preparing for different areas and
does not need to prepare for a given area continuously. The player can mix the order of
preparation days as needed.
Your task is to determine the minimum number of days required for the player to
complete all missions, or determine if it is impossible to complete them. Each mission
should be completed exactly once.
The required time complexity is less than O(nxm) and mention your proposed solution
time complexity in the code.
Input Format:
The first line contains two integers n and m the number of days in the mission period
and the number of areas respectively.
The second line contains n integers d1
, d2
,..., dn, for all 0<= di <= m where di
is the
number of the area for which a mission can be completed on day i. If di equals 0, no
mission can be completed on that day.
The third line contains m positive integers a1
, a2
,..., am for all 1<= ai <=105
, where ai
is
the number of days needed to prepare before completing a mission in area i.
Output Format:
Print one integer the minimum number of days required for the player to complete all
missions. If it is impossible, print -1.
Constraints:
1<= n, m <=105
0<= di <= m
1<= ai <=105
Example 1:
72
0102102
21
Output: 5
Example 2:
51
11111
5
Output: -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!