Benchmark AI / Public workspace
Humanity's Last Code Exam / 2011_F / Machine Works
Problem
Answer published by the source. Consult the official source to check your work against its answer.
platform
atcoder
question content
## Problem Description
You are the director of Arbitrarily Complex Machines (ACM for short), a company producing advanced machinery using even more advanced machinery. The old production machinery has broken down, so you need to buy new production machines for the company. Your goal is to make as much money as possible during the restructuring period. During this period you will be able to buy and sell machines and operate them for profit while ACM owns them. Due to space restrictions, ACM can own at most one machine at a time.
During the restructuring period, there will be several machines for sale. Being an expert in the advanced machines market, you already know the price and the availability day for each machine . Note that if you do not buy machine on day , then somebody else will buy it and it will not be available later. Needless to say, you cannot buy a machine if ACM has less money than the price of the machine.
If you buy a machine on day , then ACM can operate it starting on day . Each day that the machine operates, it produces a profit of dollars for the company.
You may decide to sell a machine to reclaim a part of its purchase price any day after you’ve bought it. Each machine has a resale price for which it may be resold to the market. You cannot operate a machine on the day that you sell it, but you may sell a machine and use the proceeds to buy a new machine on the same day.
Once the restructuring period ends, ACM will sell any machine that it still owns. Your task is to maximize the amount of money that ACM makes during the restructuring.
## Input
The input consists of several test cases. Each test case starts with a line containing three positive integers , , and . is the number of machines for sale (), is the number of dollars with which the company begins the restructuring (), and is the number of days that the restructuring lasts ().
Each of the next lines describes a single machine for sale. Each line contains four integers , , , and , denoting (respectively) the day on which the machine is for sale, the dollar price for which it may be bought, the dollar price for which it may be resold, and the daily profit generated by operating the machine. These numbers satisfy , , and .
The last test case is followed by a line containing three zeros.
## Output
For each test case, display its case number followed by the largest number of dollars that ACM can have at the end of day .
Follow the format of the sample output.
## Sample Input
Plain-text mathematical notation (without MathML)
## Problem Description You are the director of Arbitrarily Complex Machines (ACM for short), a company producing advanced machinery using even more advanced machinery. The old production machinery has broken down, so you need to buy new production machines for the company. Your goal is to make as much money as possible during the restructuring period. During this period you will be able to buy and sell machines and operate them for profit while ACM owns them. Due to space restrictions, ACM can own at most one machine at a time. During the restructuring period, there will be several machines for sale. Being an expert in the advanced machines market, you already know the price P_(i) and the availability day D_(i) for each machine M_(i). Note that if you do not buy machine M_(i) on day D_(i), then somebody else will buy it and it will not be available later. Needless to say, you cannot buy a machine if ACM has less money than the price of the machine. If you buy a machine M_(i) on day D_(i), then ACM can operate it starting on day D_(i)+1. Each day that the machine operates, it produces a profit of G_(i) dollars for the company. You may decide to sell a machine to reclaim a part of its purchase price any day after you’ve bought it. Each machine has a resale price R_(i) for which it may be resold to the market. You cannot operate a machine on the day that you sell it, but you may sell a machine and use the proceeds to buy a new machine on the same day. Once the restructuring period ends, ACM will sell any machine that it still owns. Your task is to maximize the amount of money that ACM makes during the restructuring. ## Input The input consists of several test cases. Each test case starts with a line containing three positive integers N, C, and D. N is the number of machines for sale (N≤10⁵), C is the number of dollars with which the company begins the restructuring (C≤10⁹), and D is the number of days that the restructuring lasts (D≤10⁹). Each of the next N lines describes a single machine for sale. Each line contains four integers D_(i), P_(i), R_(i), and G_(i), denoting (respectively) the day on which the machine is for sale, the dollar price for which it may be bought, the dollar price for which it may be resold, and the daily profit generated by operating the machine. These numbers satisfy 1≤D_(i)≤D, 1≤R_(i)<P_(i)≤10⁹, and 1≤G_(i)≤10⁹. The last test case is followed by a line containing three zeros. ## Output For each test case, display its case number followed by the largest number of dollars that ACM can have at the end of day D+1. Follow the format of the sample output. ## Sample Input
Original LaTeX notation
## Problem Description You are the director of Arbitrarily Complex Machines (ACM for short), a company producing advanced machinery using even more advanced machinery. The old production machinery has broken down, so you need to buy new production machines for the company. Your goal is to make as much money as possible during the restructuring period. During this period you will be able to buy and sell machines and operate them for profit while ACM owns them. Due to space restrictions, ACM can own at most one machine at a time. During the restructuring period, there will be several machines for sale. Being an expert in the advanced machines market, you already know the price \( P_i \) and the availability day \( D_i \) for each machine \( M_i \). Note that if you do not buy machine \( M_i \) on day \( D_i \), then somebody else will buy it and it will not be available later. Needless to say, you cannot buy a machine if ACM has less money than the price of the machine. If you buy a machine \( M_i \) on day \( D_i \), then ACM can operate it starting on day \( D_i + 1 \). Each day that the machine operates, it produces a profit of \( G_i \) dollars for the company. You may decide to sell a machine to reclaim a part of its purchase price any day after you’ve bought it. Each machine has a resale price \( R_i \) for which it may be resold to the market. You cannot operate a machine on the day that you sell it, but you may sell a machine and use the proceeds to buy a new machine on the same day. Once the restructuring period ends, ACM will sell any machine that it still owns. Your task is to maximize the amount of money that ACM makes during the restructuring. ## Input The input consists of several test cases. Each test case starts with a line containing three positive integers \( N \), \( C \), and \( D \). \( N \) is the number of machines for sale (\( N \leq 10^5 \)), \( C \) is the number of dollars with which the company begins the restructuring (\( C \leq 10^9 \)), and \( D \) is the number of days that the restructuring lasts (\( D \leq 10^9 \)). Each of the next \( N \) lines describes a single machine for sale. Each line contains four integers \( D_i \), \( P_i \), \( R_i \), and \( G_i \), denoting (respectively) the day on which the machine is for sale, the dollar price for which it may be bought, the dollar price for which it may be resold, and the daily profit generated by operating the machine. These numbers satisfy \( 1 \leq D_i \leq D \), \( 1 \leq R_i < P_i \leq 10^9 \), and \( 1 \leq G_i \leq 10^9 \). The last test case is followed by a line containing three zeros. ## Output For each test case, display its case number followed by the largest number of dollars that ACM can have at the end of day \( D + 1 \). Follow the format of the sample output. ## Sample Input
Code
6 10 20
6 12 1 3
1 9 1 2
3 2 1 2
8 20 5 4
4 11 7 4
2 10 9 1
0 0 0
## Output for the Sample Input
Code
Case 1: 44
question title
Machine Works
Discussion
No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
Source and history
initial import