All ICPC entries
Competitive Programming

ICPC 2015 - G. Pipe Stream

State the problem in your own words. Focus on the mathematical or algorithmic core rather than repeating the full statement.

Source sync Apr 19, 2026
Track ICPC
Year 2015
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2015/G-pipe-stream
ICPC2015TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2015/G-pipe-stream. Edit competitive_programming/icpc/2015/G-pipe-stream/solution.tex to update the written solution and competitive_programming/icpc/2015/G-pipe-stream/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
                                           Pipe Stream
                                     Time limit: 2 seconds
Your hometown has hired some contractors – including you! – to man-
age its municipal pipe network. They built the network, at great ex-
pense, to supply Flubber to every home in town. Unfortunately, no-
body has found a use for Flubber yet, but never mind. It was a Flubber
network or a fire department, and honestly, houses burn down so rarely,
a fire department hardly seems necessary.
In the possible event that somebody somewhere decides they want
some Flubber, they would like to know how quickly it will flow
through the pipes. Measuring its rate of flow is your job.
You have access to one of the pipes connected to the network. The
pipe is l meters long, and you can start the flow of Flubber through this
pipe at a time of your choosing. You know that it flows with a constant
real-valued speed, which is at least v1 meters/second and at most v2
                                                                                     Picture by Nevit via Wikimedia Commons
meters/second. You want to estimate this speed with an absolute error
of at most 2t meters/second.
Unfortunately, the pipe is opaque, so the only thing you can do is to knock on the pipe at any point along
its length, that is, in the closed real-valued range [0, l]. Listening to the sound of the knock will tell you
whether or not the Flubber has reached that point. You are not infinitely fast. Your first knock must be
at least s seconds after starting the flow, and there must be at least s seconds between knocks.
Determine a strategy that will require the fewest knocks, in the worst case, to estimate how fast the
Flubber is flowing. Note that in some cases the desired estimation might be impossible (for example, if
the Flubber reaches the end of the pipe too quickly).

Input

The input consists of multiple test cases. The first line of input contains an integer c (1 ≤ c ≤ 100), the
number of test cases. Each of the next c lines describes one test case. Each test case contains the five
integers l, v1 , v2 , t and s (1 ≤ l, v1 , v2 , t, s ≤ 109 and v1 < v2 ), which are described above.

Output

For each test case, display the minimal number of knocks required to estimate the flow speed in the worst
case. If it might be impossible to measure the flow speed accurately enough, display impossible
instead.

Sample Input 1                               Sample Output 1
3                                            5
1000 1 30 1 1                                3
60 2 10 2 5                                  impossible
59 2 10 2 5

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

  1. Describe the data structures and the state maintained by the algorithm.

  2. Explain the processing order and why it is sufficient.

  3. 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.

C++ competitive_programming/icpc/2015/G-pipe-stream/solution.cpp

Exact copied implementation source.

Raw file
#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.

TeX write-up competitive_programming/icpc/2015/G-pipe-stream/solution.tex

Exact copied write-up source.

Raw file
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{enumitem}

\title{ICPC World Finals 2015\\G. Pipe Stream}
\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}