Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

=+2. Do any of your responses and sources of conflict surprise you?

Answered: 1 week ago

Question

QueSion

Answered: 1 week ago