H. Scenery
event sponsor ICPC 2017 Problem H Scenery Time limit: 6 seconds Images by John Fowler, Carol Highsmith, and Richard Woodland You have decided to spend a day of your trip to Rapid City taking photographs of the South Dakota Badlands, which are renowned for t...
Problem Statement
Formatted from the contest statement text, with sample tests broken out into copyable blocks.
Images by John Fowler, Carol Highsmith, and Richard Woodland
You have decided to spend a day of your trip to Rapid City taking photographs of the South Dakota Badlands, which are renowned for their spectacular and unusual land formations. You are an amateur photographer, yet very particular about lighting conditions. After some careful research, you have located a beautiful location in the Badlands, surrounded by pic- turesque landscapes. You have determined a variety of features that you wish to photograph from this location. For each feature you have identified the earliest and latest time of day at which the position of the sun is ideal. However, it will take quite a bit of time to take each photograph, given the need to repo- sition the tripod and camera and your general perfectionism. So you are wondering if it will be possible to successfully take photographs of all these features in one day.
Input
The first line of the input contains two integers n (1 ≤ n ≤ 104 ) and t (1 ≤ t ≤ 105 ), where n is the number of desired photographs and t is the time you spend to take each photograph. Following that are n additional lines, each describing the available time period for one of the photographs. Each such line contains two nonnegative integers a and b, where a is the earliest time that you may begin working on that photograph, and b is the time by which the photograph must be completed, with a + t ≤ b ≤ 109 .
Output
Display yes if it is possible to take all n photographs, and no otherwise.
Rapid City
sponsor
ICPC 2017Sample Tests
2 10
0 15
5 20 yes 2 10
1 15
0 20 no 2 10
5 30
10 20 yes Editorial
The solution write-up is rendered from the LaTeX source, with equations kept live through MathJax.
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
C++ solution used for this page.
#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 and Assets
Raw files are still available here when you want the original TeX, C++, or statement assets.
Show raw files
competitive_programming/icpc/2017/H-scenery/solution.texC++ implementationcompetitive_programming/icpc/2017/H-scenery/solution.cppStatement textcompetitive_programming/icpc/2017/H-scenery/statement.txtStatement PDFcompetitive_programming/icpc/2017/H-scenery/statement.pdfMetadatacompetitive_programming/icpc/2017/H-scenery/meta.jsonYear packetcompetitive_programming/icpc/2017/contest_problems.pdf