All ICPC entries
Competitive Programming

ICPC 2011 - E. Coffee Central

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 2011
Files TeX, C++, statement assets
Folder competitive_programming/icpc/2011/E-coffee-central
ICPC2011TeXC++statement textstatement pdf

Source-first archive entry

This page is built from the copied files in competitive_programming/icpc/2011/E-coffee-central. Edit competitive_programming/icpc/2011/E-coffee-central/solution.tex to update the written solution and competitive_programming/icpc/2011/E-coffee-central/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 E
                                               Coffee Central
                                              Problem ID: coffee
Is it just a fad or is it here to stay? You’re not sure, but the steadily increasing number of coffee shops that are opening
in your hometown has certainly become quite a draw. Apparently, people have become so addicted to coffee that
apartments that are close to many coffee shops will actually fetch higher rents.
This has come to the attention of a local real-estate company. They are interested in identifying the most valuable
locations in the city in terms of their proximity to large numbers of coffee shops. They have given you a map of the
city, marked with the locations of coffee shops. Assuming that the average person is willing to walk only a fixed
number of blocks for their morning coffee, you have to find the location from which one can reach the largest number
of coffee shops. As you are probably aware, your hometown is built on a square grid layout, with blocks aligned on
north-south and east-west axes. Since you have to walk along streets, the distance between intersections (a, b) and
(c, d) is |a − c| + |b − d|.

Input

The input contains several test cases. Each test case describes a city. The first line of each test case contains four
integers dx, dy, n, and q. These are the dimensions of the city grid dx × dy (1 ≤ dx, dy ≤ 1000), the number of
coffee shops n (0 ≤ n ≤ 5 · 105 ), and the number of queries q (1 ≤ q ≤ 20). Each of the next n lines contains two
integers xi and yi (1 ≤ xi ≤ dx, 1 ≤ yi ≤ dy); these specify the location of the ith coffee shop. There will be at most
one coffee shop per intersection. Each of the next q lines contains a single integer m (0 ≤ m ≤ 106 ), the maximal
distance that a person is willing to walk for a cup of coffee.
The last test case is followed by a line containing four zeros.

Output

For each test case in the input, display its case number. Then display one line per query in the test case. Each line
displays the maximum number of coffee shops reachable for the given query distance m followed by the optimal
location. For example, the sample output shows that 3 coffee shops are within query distance 1 of the optimal location
(3, 4), 4 shops are within query distance 2 of optimal location (2, 2), and 5 shops are within query distance 4 of optimal
location (3, 1). If there are multiple optimal locations, pick the location that is furthest south (minimal positive integer
y-coordinate). If there is still a tie, pick the location furthest west (minimal positive integer x-coordinate).
Follow the format of the sample output.

ICPC 2011 World Finals Problem E: Coffee Central

 Sample input                                      Output for the Sample Input
 4   4 5 3                                         Case 1:
 1   1                                             3 (3,4)
 1   2                                             4 (2,2)
 3   3                                             5 (3,1)
 4   4
 2   4
 1
 2
 4
 0   0 0 0

ICPC 2011 World Finals Problem E: Coffee Central

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/2011/E-coffee-central/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/2011/E-coffee-central/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 2011\\E. Coffee Central}
\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}