Problem Description The local pie shop is offering a promotion - all-you-can-eat pies! Obviously, you can't pass up this offer. The shop lines up N pies from left to right - the ith pie contains A, grams of sugar. Additionally, another M pies are provided - the ith of these contains B, grams of sugar. You are first allowed to insert each of the M pies from the second group anywhere into the first list of N pies, such as at its start or end, or in between any two pies already in the list. The result will be a list of N + M pies with the constraint that the initial N pies are still in their original relative order. Following this, you are allowed to take one walk along the new line of pies from left to right, to pick up your selection of all-you-can-eat pies! When you arrive at a pie, you may choose to add it to your pile, or skip it. However, because you're required to keep moving, if you pick up a certain pie, you will not be able to also pick up the pie immediately after it (if any). In other words, you cannot eat consecutive pies in this combined list. Being a pie connoisseur, your goal is to maximize the total amount of sugar in the pies you pick up from the line. How many grams can you get? Input Specification The first line of input contains the integer N (1SN < 300). The next N lines contain one integer A; (1 < A, < 10*), describing the integer number of grams of sugar in pie i in the group of N pies. The next line contains M (0 < M < 100), the number of pies in the second list. The next M lines contain one integer B, (1< B, < 10°), describing the integer number of grams of sugar in pie i in the group of M pies. Output Specification Output the maximum number of grams of sugar in all the pies that you are able to pick up. Sample Input 5. 10 12 6. 14

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

A code in c# please ...

thanks

3
1
Output for Sample Input
44
Explanation of Output for Sample Input
Place the pies in the order
10, 1, 12, 2, 8, 6, 14, 7
(that is, insert the pie with 1 gram of sugar between 10 and 12, and insert pies with 2 and 8 grams
of sugar, in that order, between pies 12 and 6). Then, we can grab 10 + 12 + 8+ 14 = 44 grams
of sugar, which is maximal.
Transcribed Image Text:3 1 Output for Sample Input 44 Explanation of Output for Sample Input Place the pies in the order 10, 1, 12, 2, 8, 6, 14, 7 (that is, insert the pie with 1 gram of sugar between 10 and 12, and insert pies with 2 and 8 grams of sugar, in that order, between pies 12 and 6). Then, we can grab 10 + 12 + 8+ 14 = 44 grams of sugar, which is maximal.
Problem Description
The local pie shop is offering a promotion - all-you-can-eat pies! Obviously, you can't pass up this
offer.
The shop lines up N pies from left to right - the ith pie contains A, grams of sugar. Additionally,
another M pies are provided - the ith of these contains B grams of sugar.
You are first allowed to insert each of the M pies from the second group anywhere into the first list
N pies, such as at its start or end, or in between any two pies already in the list. The result will
be a list of N + M pies with the constraint that the initial N pies are still in their original relative
order.
Following this, you are allowed to take one walk along the new line of pies from left to right, to
pick up your selection of all-you-can-eat pies! When you arrive at a pie, you may choose to add it
to your pile, or skip it. However, because you're required to keep moving, if you pick up a certain
pie, you will not be able to also pick up the pie immediately after it (if any). In other words, you
cannot eat consecutive pies in this combined list.
Being a pie connoisseur, your goal is to maximize the total amount of sugar in the pies you pick
up from the line. How many grams can you get?
Input Specification
The first line of input contains the integer N (1 <N< 3000). The next N lines contain one
integer A; (1 < A < 10°), describing the integer number of grams of sugar in pie i in the group
of N pies.
The next line contains M (0 < M < 100), the number of pies in the second list. The next M lines
contain one integer B, (1< B, < 10*), describing the integer number of grams of sugar in pie i in
the group of M pies.
Output Specification
Output the maximum number
grams of sugar in all the pies that you are able to pick up.
Sample Input
5
10
12
6
14
7
Transcribed Image Text:Problem Description The local pie shop is offering a promotion - all-you-can-eat pies! Obviously, you can't pass up this offer. The shop lines up N pies from left to right - the ith pie contains A, grams of sugar. Additionally, another M pies are provided - the ith of these contains B grams of sugar. You are first allowed to insert each of the M pies from the second group anywhere into the first list N pies, such as at its start or end, or in between any two pies already in the list. The result will be a list of N + M pies with the constraint that the initial N pies are still in their original relative order. Following this, you are allowed to take one walk along the new line of pies from left to right, to pick up your selection of all-you-can-eat pies! When you arrive at a pie, you may choose to add it to your pile, or skip it. However, because you're required to keep moving, if you pick up a certain pie, you will not be able to also pick up the pie immediately after it (if any). In other words, you cannot eat consecutive pies in this combined list. Being a pie connoisseur, your goal is to maximize the total amount of sugar in the pies you pick up from the line. How many grams can you get? Input Specification The first line of input contains the integer N (1 <N< 3000). The next N lines contain one integer A; (1 < A < 10°), describing the integer number of grams of sugar in pie i in the group of N pies. The next line contains M (0 < M < 100), the number of pies in the second list. The next M lines contain one integer B, (1< B, < 10*), describing the integer number of grams of sugar in pie i in the group of M pies. Output Specification Output the maximum number grams of sugar in all the pies that you are able to pick up. Sample Input 5 10 12 6 14 7
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education