In this problem you will be solving one of the most profound challenges of humans across...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this problem you will be solving one of the most profound challenges of humans across the world since the beginning of time - how to make lots of money. You are a middleman in the widget market. Your job is to buy widgets from widget producer companies and sell them to widget consumer companies. Each widget consumer company has an open request for one widget per day, until some end date, and a price at which it is willing to buy the widgets. On the other hand, each widget producer company has a start date at which it can start delivering widgets and a price at which it will deliver each widget. Due to fair competition laws, you can sign a contract with only one producer company and only one consumer company. You will buy widgets from the producer company, one per day, starting on the day it can start delivering, and ending on the date specified by the consumer company. On each of those days you earn the difference between the producer's selling price and the consumer's buying price. Your goal is to choose the consumer company and the producer company that will maximize your profits. Input The first line of input contains two integers m and n (1 <= m; n <= 500 000) denoting the number of producer and consumer companies in the market, respectively. It is followed by m lines, the ith of which contains two integers p; and d; (1 <= Pi d; <= 109), the price (in dollars) at which the ith producer sells one widget and the day on which the first widget will be available from this company. Then follow n lines, the jth of which contains two integers q; and e; (1 <=q; ; ; <= 109), the price (in dollars) at which the jth consumer is willing to buy widgets and the day immediately after the day on which the last widget has to be delivered to this company. Output Display the maximum total number of dollars you can earn. If there is no way to sign contracts that gives you any profit, display 0. Input Samples Output Samples 22 1 3 2 1 3 5 7 2 1 2 10 10 9 11 11 9 5 0 In this problem you will be solving one of the most profound challenges of humans across the world since the beginning of time - how to make lots of money. You are a middleman in the widget market. Your job is to buy widgets from widget producer companies and sell them to widget consumer companies. Each widget consumer company has an open request for one widget per day, until some end date, and a price at which it is willing to buy the widgets. On the other hand, each widget producer company has a start date at which it can start delivering widgets and a price at which it will deliver each widget. Due to fair competition laws, you can sign a contract with only one producer company and only one consumer company. You will buy widgets from the producer company, one per day, starting on the day it can start delivering, and ending on the date specified by the consumer company. On each of those days you earn the difference between the producer's selling price and the consumer's buying price. Your goal is to choose the consumer company and the producer company that will maximize your profits. Input The first line of input contains two integers m and n (1 <= m; n <= 500 000) denoting the number of producer and consumer companies in the market, respectively. It is followed by m lines, the ith of which contains two integers p; and d; (1 <= Pi d; <= 109), the price (in dollars) at which the ith producer sells one widget and the day on which the first widget will be available from this company. Then follow n lines, the jth of which contains two integers q; and e; (1 <=q; ; ; <= 109), the price (in dollars) at which the jth consumer is willing to buy widgets and the day immediately after the day on which the last widget has to be delivered to this company. Output Display the maximum total number of dollars you can earn. If there is no way to sign contracts that gives you any profit, display 0. Input Samples Output Samples 22 1 3 2 1 3 5 7 2 1 2 10 10 9 11 11 9 5 0
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
In this problem you will compute January 12 2004 bid and ask volatilities (using the Black-Scholes implied volatility function) for 1-year IBM options expiring the following January. Note that IBM...
-
World War II was one of the most significant events in world history, and certainly for the United States. The war fundamentally changed the way America viewed its role in the world and it redefined...
-
One of the most efficient heat engines ever built is a steam turbine in the Ohio valley, operating between 430C and 1 870C on energy from West Virginia coal to produce electricity for the Midwest....
-
Find the derivative of the function. y = e x-4
-
A machine that cuts corks for wine bottles operates in such a way that the distribution of the diameter of the corks produced is well approximated by a normal distribution with mean 3 centimeters and...
-
Madsen Company had five convertible securities outstanding during all of 2007. It paid the appropriate interest (and amortized any related premium or discount using the straight-line method) and...
-
The plaintiff worked in a maintenance department for the defendant, a railway company, as a forklift operator. She was the only female worker in that department, and her supervisor repeatedly told...
-
Libra Company is purchasing 100% of the outstanding stock of Genall Company for $700,000. Genall has the following balance sheet on the date of acquisition: Appraisals indicate that the following...
-
6. The number of (staircase) paths in the xy-plane from (0, 0) to (7, 5) where each such path is made up of individual steps going one unit upward (U) or one unit to the right (R). (a) 12C5 (b) 12!...
-
Assign the jobs 1, 2, 3, to machines A, B, C using the assignment method and calculate the total time of your assignments. The estimated job completion times in hours are given in the table below....
-
The company shows you the following financial information for the 12-Month periods ended: 2018 2019 Sales 10,000,000 $15,000,000 COGS 5,900,000 8,800,000 Gross Profit 4,100,000 (41.0%) 6,200,000...
-
Explain why the banking system was so unstable prior to the establishment of the Federal Reserve System in 1914.
-
Since 2013, Japan has been struggling to raise the countrys inflation rate from about 0 percent to 2 percent. According to an article in the Wall Street Journal, Japan aimed to raise its inflation...
-
What does the payback method use to rank projects? a. How long the invested money is at risk b. The relative size of the potential profit c. The number of years the well will be producing d. The size...
-
In project analysis, which method(s) do not permit the ranking of several competing investment options? a. Payback method b. Accounting rate of return c. Net present value d. Internal rate of return...
-
Stephens Company operates a single field in Wyoming in which it has a 48% working interest. The remainder of the working interest is held by another oil company. The field went onto production in...
-
Prove the following relations: (C) Toct (12-312)1/2 3 (d) = ($152 + 8253 + $381).
-
Jax Incorporated reports the following data for its only product. The company had no beginning finished goods inventory and it uses absorption costing. $ 57.30 per unit $ 10.30 per unit $ 7.80 per...
-
Identify from Cresseys research the six situational categories that cause nonshareable problems.
-
A scientist has two bucketsone holds 4 gallons and the other holds 5 gallonsas well as an unlimited water supply. By using nothing but the buckets and water, how can you accurately measure 3 gallons...
-
Which of the following is true with regard to Cresseys theory of crime causation? 1. For a fraud to occur, only one of the fraud triangle attributes (perceived pressure, perceived opportunity, or...
Study smarter with the SolutionInn App