ICPC 2016
ICPC 2016

J. Spin Doctor

As an employee of the world’s most respected political polling corporation, you must take complex, real- world issues and simplify them down to a few numbers. It isn’t always easy. A big election is coming up and, at the request of Candidate X, you have jus...

Updated May 21, 2026
Track ICPC
Year 2016
Statement Text + PDF
TeXC++Statement textStatement PDF

Problem Statement

Formatted from the contest statement text, with sample tests broken out into copyable blocks.

Time limit 5 seconds

As an employee of the world’s most respected political polling corporation, you must take complex, real- world issues and simplify them down to a few numbers. It isn’t always easy. A big election is coming up and, at the request of Candidate X, you have just finished polling n people. You have gathered three pieces of information from each person, with the values for the ith person recorded as:

  • ai – the number of digits of π they have memorized
  • bi – the number of hairs on their head
  • ci – whether they will vote for Candidate X

Unfortunately, you are beginning to wonder if these are really the most relevant questions to ask. In fact, you cannot see any correlation between a, b, and c in the data. Of course, you cannot just contradict your customer – that is a good way to lose your job! Perhaps the answer is to find some weighting formula to make the results look meaningful. You will pick two real values S and T , and sort the poll results (ai , bi , ci ) by the measure ai · S + bi · T . The sort will look best if the results having ci true are clustered as close to each other as possible. More precisely, if j and k are the indices of the first and last results with ci true, you want to minimize the cluster size which is k − j + 1. Note that some choices of S and T will result in ties among the (ai , bi , ci ) triples. When this happens, you should assume the worst possible ordering occurs (that which maximizes the cluster size for this (S, T ) pair).

Input

The input starts with a line containing n (1 ≤ n ≤ 250 000), which is the number of people polled. This is followed by one line for each person polled. Each of those lines contains integers ai (0 ≤ ai ≤ 2 000 000), bi (0 ≤ bi ≤ 2 000 000), and ci , where ci is 1 if the person will vote for Candidate X and 0 otherwise. The input is guaranteed to contain at least one person who will vote for Candidate X.

Output

Display the smallest possible cluster size over all possible (S, T ) pairs.

Sample Tests

Sample 1
Sample Input
 6
 0 10 0
 10 0 1
 12 8 1
 5 5 0
 11 2 1
 11 3 0
Sample Output
4
Sample 2
Sample Input
10
6 1     1
0 2     0
2 1     1
6 1     1
8 2     0
4 4     0
4 0     0
2 3     1
6 1     0
6 3     1
Sample Output
8
Sample 3
Sample Input
5
5   7   0
3   4   0
5   7   0
5   7   1
9   4   0
Sample Output
1

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

  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

C++ solution used for this page.

C++

Clean code view with a raw-file link when you want the original 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 and Assets

Raw files are still available here when you want the original TeX, C++, or statement assets.

Show raw files