Benchmark AI / Public workspace
Humanity's Last Code Exam / 2020_G / Opportunity Cost
Problem
Answer published by the source. Consult the official source to check your work against its answer.
platform
atcoder
question content
## Problem Description
As with most types of products, buying a new phone can be difficult. One of the main challenges is that there are a lot of different aspects of the phone that you might care about, such as its price, its performance, and how user-friendly the phone is. Typically, there will be no single phone that is simultaneously the best at all of these things: the cheapest phone, the most powerful phone, and the most user-friendly phone will likely be different phones.
Thus when buying a phone, you are forced to make some sacrifices by balancing the different aspects you care about against each other and choosing the phone that achieves the best compromise (where “best” of course depends on what your priorities happen to be). One way of measuring this sacrifice is known as the opportunity cost, which (for the purposes of this problem) we define as follows.
Suppose that you have bought a phone with price , performance , and user-friendliness . For simplicity, we assume that these three values are measured on a comparable numeric scale where higher is better. If there are available phones, and the values represent the (price, performance, user-friendliness) of the -th phone, then the opportunity cost of your phone is defined as:
Write a program that, given the list of available phones, finds a phone with the minimum opportunity cost.
## Input
- The first line of input contains an integer (), the number of phones considered.
- Following that are lines. The -th of these lines contains three integers , , and , where is the price, is the performance, and is the user-friendliness of the -th phone ().
## Output
- Output a single line containing two integers: the smallest possible opportunity cost and an integer between 1 and indicating the phone achieving that opportunity cost. If there are multiple such phones, output the one with the smallest index.
## Sample Input 1
Plain-text mathematical notation (without MathML)
## Problem Description As with most types of products, buying a new phone can be difficult. One of the main challenges is that there are a lot of different aspects of the phone that you might care about, such as its price, its performance, and how user-friendly the phone is. Typically, there will be no single phone that is simultaneously the best at all of these things: the cheapest phone, the most powerful phone, and the most user-friendly phone will likely be different phones. Thus when buying a phone, you are forced to make some sacrifices by balancing the different aspects you care about against each other and choosing the phone that achieves the best compromise (where “best” of course depends on what your priorities happen to be). One way of measuring this sacrifice is known as the opportunity cost, which (for the purposes of this problem) we define as follows. Suppose that you have bought a phone with price x, performance y, and user-friendliness z. For simplicity, we assume that these three values are measured on a comparable numeric scale where higher is better. If there are n available phones, and the values (x_(i),y_(i),z_(i)) represent the (price, performance, user-friendliness) of the i-th phone, then the opportunity cost of your phone is defined as: max_(1≤i≤n)(max(x_(i)−x,0)+max(y_(i)−y,0)+max(z_(i)−z,0)) Write a program that, given the list of available phones, finds a phone with the minimum opportunity cost. ## Input - The first line of input contains an integer n (2≤n≤200,000), the number of phones considered. - Following that are n lines. The i-th of these lines contains three integers x_(i), y_(i), and z_(i), where x_(i) is the price, y_(i) is the performance, and z_(i) is the user-friendliness of the i-th phone (1≤x_(i),y_(i),z_(i)≤10⁹). ## Output - Output a single line containing two integers: the smallest possible opportunity cost and an integer between 1 and n indicating the phone achieving that opportunity cost. If there are multiple such phones, output the one with the smallest index. ## Sample Input 1
Original LaTeX notation
## Problem Description
As with most types of products, buying a new phone can be difficult. One of the main challenges is that there are a lot of different aspects of the phone that you might care about, such as its price, its performance, and how user-friendly the phone is. Typically, there will be no single phone that is simultaneously the best at all of these things: the cheapest phone, the most powerful phone, and the most user-friendly phone will likely be different phones.
Thus when buying a phone, you are forced to make some sacrifices by balancing the different aspects you care about against each other and choosing the phone that achieves the best compromise (where “best” of course depends on what your priorities happen to be). One way of measuring this sacrifice is known as the opportunity cost, which (for the purposes of this problem) we define as follows.
Suppose that you have bought a phone with price \(x\), performance \(y\), and user-friendliness \(z\). For simplicity, we assume that these three values are measured on a comparable numeric scale where higher is better. If there are \(n\) available phones, and the values \((x_i, y_i, z_i)\) represent the (price, performance, user-friendliness) of the \(i\)-th phone, then the opportunity cost of your phone is defined as:
\[
\max_{1 \leq i \leq n} (\max(x_i - x, 0) + \max(y_i - y, 0) + \max(z_i - z, 0))
\]
Write a program that, given the list of available phones, finds a phone with the minimum opportunity cost.
## Input
- The first line of input contains an integer \(n\) (\(2 \leq n \leq 200,000\)), the number of phones considered.
- Following that are \(n\) lines. The \(i\)-th of these lines contains three integers \(x_i\), \(y_i\), and \(z_i\), where \(x_i\) is the price, \(y_i\) is the performance, and \(z_i\) is the user-friendliness of the \(i\)-th phone (\(1 \leq x_i, y_i, z_i \leq 10^9\)).
## Output
- Output a single line containing two integers: the smallest possible opportunity cost and an integer between 1 and \(n\) indicating the phone achieving that opportunity cost. If there are multiple such phones, output the one with the smallest index.
## Sample Input 1
Code
4
20 5 5
5 20 5
5 5 20
10 10 10
## Sample Output 1
Code
10 4
## Sample Input 2
Code
4
15 15 5
5 15 15
15 5 15
10 10 10
## Sample Output 2
Code
10 1
question title
Opportunity Cost
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