### Introduction to Competitive Programming

# Introduction to Competitive Programming

Have you heard your friends talk about LeetCode or Codeforces contests? Maybe you’re wondering what competitive programming is all about. Here’s what you need to know.

## What is Competitive Programming?

Competitive Programming (CP, or sometimes known as Informatics) is an activity where we try to solve clearly defined computational problems using code. The 'competitive' part of CP comes from the numerous contests where people aim to correctly solve as many problems as possible in a fixed timeframe, typically around two to five hours. Solutions must also follow time and memory constraints which means your code needs to be both correct and efficient.

These problems are thought to train and test you in three related areas:

Problem solving.

Algorithms and data structures, which we apply to solve problems efficiently.

Implementation, the process of writing and testing code.

Many people participate in competitive programming for the challenge and fun of it, but it is also great practice for technical interviews in software jobs, university courses, and general problem solving in the real world.

## Competitive Programming at UNSW

CPMSoc’s programming team runs regular workshops and occasional contests, suitable for all experience levels. We are always happy to give advice and help out.

We also recommend taking COMP4128 (Programming Challenges) when you are able to, as having the lecturer and tutors there to help you quickly is very useful.

The most notable university competition is the International Collegiate Programming Contest (ICPC). The contests are five hours long with roughly twelve problems, and you compete in teams of three. Generally there are three stages: the Divisionals, Regionals, and World Finals.

## Sample Problem

**N**identical flowers to arrange into three vases. As an expert in interior design, there are three important rules you must follow:

- Every flower must go into one of the vases, since throwing flowers away is wasteful.
- Each vase must contain at least one flower, since an empty vase looks very odd.
- Each vase must contain a different number of flowers, so all the vases look different.

**N**, print a possible way to arrange the flowers, or say that there is no way.

**N**as input, and outputs the number of flowers you want in each vase.

## Getting Started

### Pick your programming language

- C++ is the most commonly used language in CP, for its speed and large standard library.
- Python is easy to learn and use, but is slow, and so may not be able to solve certain problems.

### Training and contests

**Solve a really simple problem**, like Wrong Subtraction, (or*Vases*from earlier, although this isn’t on Codeforces) to get used to reading input and writing output.**Solve more problems**, of increasing difficulty. You can search problems by difficulty rating in the Problem Set.**Try some contests**. The Educational, Division 3 and Division 4 contests are targeted towards beginners.