ICPC 2016 - G. Oil
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
Source-first archive entry
This page is built from the copied files in competitive_programming/icpc/2016/G-oil. Edit
competitive_programming/icpc/2016/G-oil/solution.tex to update the written solution and
competitive_programming/icpc/2016/G-oil/solution.cpp to update the implementation.
The website does not replace those files with hand-maintained HTML. It reads the copied source tree during the build and exposes the exact files below.
Problem Statement
Copied statement text kept beside the solution archive for direct reference.
Problem G
Oil
Time limit: 10 seconds
A large part of the world economy depends on oil, which is why research into new methods for finding
and extracting oil is still active. Profits of oil companies depend in part on how efficiently they can
drill for oil. The International Crude Petroleum Consortium (ICPC) hopes that extensive computer
simulations will make it easier to determine how to drill oil wells in the best possible way.
Drilling oil wells optimally is getting harder each day – the newly discovered oil deposits often do
not form a single body, but are split into many parts. The ICPC is currently concerned with stratified
deposits, as illustrated in Figure G.1.
Surface x
(100, 20) (180, 20)
(30, 30) (60, 30)
(70, 40) (110, 40)
(10, 50) (40, 50)
(0, 70) (80, 70)
y
Figure G.1: Oil layers buried in the earth. This figure corresponds to Sample Input 1.
To simplify its analysis, the ICPC considers only the 2-dimensional case, where oil deposits are modeled
as horizontal line segments parallel to the earth’s surface. The ICPC wants to know how to place a single
oil well to extract the maximum amount of oil. The oil well is drilled from the surface along a straight
line and can extract oil from all deposits that it intersects on its way down, even if the intersection is at
an endpoint of a deposit. One such well is shown as a dashed line in Figure G.1, hitting three deposits.
In this simple model the amount of oil contained in a deposit is equal to the width of the deposit. Can
you help the ICPC determine the maximum amount of oil that can be extracted by a single well?
Input
The first line of input contains a single integer n (1 ≤ n ≤ 2 000), which is the number of oil deposits.
This is followed by n lines, each describing a single deposit. These lines contain three integers x0 ,
x1 , and y giving the deposit’s position as the line segment with endpoints (x0 , y) and (x1 , y). These
numbers satisfy |x0 |, |x1 | ≤ 106 and 1 ≤ y ≤ 106 . No two deposits will intersect, not even at a point.
Output
Display the maximum amount of oil that can be extracted by a single oil well.
Sample Input 1 Sample Output 1
5 200
100 180 20
30 60 30
70 110 40
10 40 50
0 80 70
Sample Input 2 Sample Output 2
3 25
50 60 10
-42 -42 20
25 0 10
Editorial
Rendered from the copied solution.tex file. The original TeX source remains
available below.
Key Observations
Write the structural observations that make the problem tractable.
State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
If the constraints matter, explain exactly which part of the solution they enable.
Algorithm
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
Mention corner cases explicitly if they affect the implementation.
Correctness Proof
We prove that the algorithm returns the correct answer.
Lemma 1.
State the first key claim.
Proof.
Provide a concise proof.
Lemma 2.
State the next claim if needed.
Proof.
Provide a concise proof.
Theorem.
The algorithm outputs the correct answer for every valid input.
Proof.
Combine the lemmas and finish the argument.
Complexity Analysis
State the running time and memory usage in terms of the input size.
Implementation Notes
Mention any non-obvious implementation detail that is easy to get wrong.
Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
Code
Exact copied C++ implementation from solution.cpp.
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Source Files
Exact copied source-of-truth files. Edit solution.tex for the write-up and solution.cpp for the implementation.
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}
\title{ICPC World Finals 2016\\G. Oil}
\author{}
\date{}
\begin{document}
\maketitle
\section*{Problem Summary}
State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.
\section*{Key Observations}
\begin{itemize}[leftmargin=*]
\item Write the structural observations that make the problem tractable.
\item State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
\item If the constraints matter, explain exactly which part of the solution they enable.
\end{itemize}
\section*{Algorithm}
\begin{enumerate}[leftmargin=*]
\item Describe the data structures and the state maintained by the algorithm.
\item Explain the processing order and why it is sufficient.
\item Mention corner cases explicitly if they affect the implementation.
\end{enumerate}
\section*{Correctness Proof}
We prove that the algorithm returns the correct answer.
\paragraph{Lemma 1.}
State the first key claim.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Lemma 2.}
State the next claim if needed.
\paragraph{Proof.}
Provide a concise proof.
\paragraph{Theorem.}
The algorithm outputs the correct answer for every valid input.
\paragraph{Proof.}
Combine the lemmas and finish the argument.
\section*{Complexity Analysis}
State the running time and memory usage in terms of the input size.
\section*{Implementation Notes}
\begin{itemize}[leftmargin=*]
\item Mention any non-obvious implementation detail that is easy to get wrong.
\item Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
\end{itemize}
\end{document}
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}