Home

maxn

In programming, maxn (often written as MAXN or maxN) is a conventional identifier used to denote the maximum size of a collection, such as the number of elements, nodes, or positions that a program must support. It is not a language feature; rather, it is a naming convention in source code, particularly in competitive programming templates.

Usage: In contest templates, maxn is defined as a compile-time constant to allocate static arrays or adjacency

Naming and alternatives: Variants include MAXN, NMAX, or maxN; some projects prefer more descriptive names such

Practical considerations: Choosing maxn too small causes out-of-bounds access; too large wastes memory. In languages with

Other uses: maxn can also appear in problem statements as a symbol representing the upper bound of

lists
large
enough
to
hold
the
largest
possible
input
described
in
the
problem
statement.
For
example,
in
C++:
const
int
MAXN
=
100000;
int
a[MAXN+5];
as
LIMIT
or
CAP.
In
modern
code,
some
use
constexpr
or
templates
instead
of
macros
to
avoid
macro
pitfalls.
stack
allocation,
very
large
maxn
can
cause
stack
overflow;
dynamic
containers
(vectors)
can
adjust
to
actual
input
size
but
may
add
overhead.
In
1-based
indexing,
programmers
often
allocate
maxn+5
to
provide
a
safe
margin.
n,
the
number
of
items
in
a
set.
It
is
commonly
seen
in
tutorials,
problem
solutions,
and
CP
libraries.