🏆 COMPETITIVE PROGRAMMING ARCHIVE

ICPC 2026 Thailand (Southern Region)

Official problem statements, sample test cases, algorithmic analysis, and C++ solutions from my contest repository. Click "Reveal Solution" under any problem to inspect the C++ source code.

QUICK JUMP: A B C D E F G
7 Problems
C++17 Language
100% Solutions Logged
Southern TH Region
// SELECT PROBLEM SLOT:
A

Median Person

// CONDITIONAL_SORT
⏱️ 1.0s 💾 256MB

Problem Statement

Three students each took an exam and received a score. Every score is a different integer, so exactly one student scored higher than exactly one other and lower than the remaining one — that student's score is the median: it is neither the highest nor the lowest of the three.

Given the three students' names and their scores, determine the name of the student who scored the median.

Input Format

Line 1: Three names separated by single spaces (lowercase English letters).
Line 2: Three integers separated by single spaces (scores between 0 and 100, pairwise distinct).

Output Format

Print a single line containing the name of the student whose score is the median of the three.

Sample Testcases

Input 1
ann bob cid
5 2 8
Output 1
ann
Input 2
x y z
8 5 2
Output 2
y
Note: In sample 1, ann = 5, bob = 2, cid = 8. The median score 5 belongs to ann.
B

Holy Triangle Talisman

// GEOMETRY_INEQUALITY
⏱️ 1.0s 💾 256MB

Problem Statement

Jack bought three holy bamboos. Each bamboo initially had length A units. Since then, the bamboos have experienced 0, 1, and 2 moonrises respectively. Whenever a moonrise occurs, a bamboo grows by B units.

The lengths of the three bamboos are therefore A, A + B, and A + 2B. To fend off an invasion using a Holy Circle Talisman, Jack must arrange the three bamboos so that their tips connect to form a valid non-degenerate triangle. Determine whether the three bamboos can form a triangle.

Input Format

Single line containing two integers A and B (1 ≤ A, B ≤ 500).

Output Format

Print Yes if the three bamboos can form a triangle, or No otherwise.

Sample Testcases

Input 1
3 1
Output 1
Yes
Input 2
1 2
Output 2
No
Note: Three side lengths x, y, z form a valid triangle if and only if the sum of any two lengths is strictly greater than the remaining length. Since side A + 2B is the longest, the condition simplifies to A + (A + B) > A + 2B, which simplifies to 2A + B > A + 2B (or A > B).
C

Movie Seat

// STRING_TRAVERSAL
⏱️ 1.0s 💾 256MB

Problem Statement

The front row of a movie theater consists of seats arranged in a straight line represented by a string S:

  • x indicates that the seat is occupied by another guest.
  • o indicates that the seat is currently empty.

You want to sit in an empty seat (o) without disturbing anyone. You can only pick an empty seat whose adjacent seats (if they exist) are also empty. Determine how many seats in the row you can choose from.

Input Format

Single string S (1 ≤ |S| ≤ 5000), representing the arrangement of seats in the front row.

Output Format

Print a single integer: the number of valid empty seats you can choose to sit on.

Sample Testcases

Input 1
ooxoooooxo
Output 1
3
Input 2
xoxx
Output 2
0
Note: In sample 1, seats at index 1, 5, and 6 (1-indexed) are empty and surrounded only by empty seats, yielding 3 valid choices.
D

Leftover

// GREEDY_OPTIMIZATION
⏱️ 1.0s 💾 256MB

Problem Statement

Captain Tsubasa and his pirate crew discovered N treasure chests containing A1, A2, ..., AN gold coins.

However, they are short by exactly one crew member! Each pirate can carry at most 1 chest, so exactly 1 chest must be left behind. Gold coins cannot be split between chests. Calculate the maximum total number of gold coins the crew can carry back to the ship.

Input Format

Line 1: Integer N (2 ≤ N ≤ 100).
Line 2: N integers A1, A2, ..., AN (1 ≤ Ai ≤ 1000).

Output Format

Print a single integer: the maximum total gold coins carried by the N - 1 crew members.

Sample Testcases

Input 1
5
3 6 7 4 6
Output 1
23
Note: Leaving behind the smallest chest (3 gold coins) yields 6 + 7 + 4 + 6 = 23 coins, which maximizes the sum.
E

No lemon, no melon

// PALINDROME_CONSTRUCTION
⏱️ 1.0s 💾 256MB

Problem Statement

Hannah is a math professor obsessed with palindromes. Your friend has prepared A lemons. You want to buy B melons such that the total number of fruits A + B is a numeric palindrome.

Given A (1 ≤ A ≤ 1012), find a valid B (1 ≤ B ≤ 1012) such that A + B reads the same forwards and backwards.

Input Format

Single line containing an integer A (1 ≤ A ≤ 1012).

Output Format

Print a single integer B (1 ≤ B ≤ 1012). If multiple valid answers exist, print any.

Sample Testcases

Input 1
67
Output 1
10
Input 2
998244353
Output 2
1755646
Note: For 67, 67 + 10 = 77 (palindrome). For 998244353, 998244353 + 1755646 = 999999999 (palindrome).
F

Upscaling

// GRID_TRANSFORMATION
⏱️ 1.0s 💾 256MB

Problem Statement

An original image of resolution N × M pixels is upscaled by an integer factor K. Each original pixel expands into a K × K block, producing an upscaled grid of size (N · K) × (M · K).

You crop the upscaled image from row r1 to r2 and column c1 to c2. Compute the number of distinct pixels from the original image that overlap with the cropped area.

Input Format

Line 1: T (1 ≤ T ≤ 104) testcases.
Each testcase contains 7 integers: N M K r1 c1 r2 c2.

Output Format

For each testcase, print the number of distinct original pixels in the crop region.

Sample Testcases

Input 1
1
3 3 3 2 4 5 7
Output 1
4
G

EV Charging

// TWO_POINTERS_GREEDY
⏱️ 2.0s 💾 256MB

Problem Statement

An EV charging station has N reservation requests. The i-th request asks to charge starting at time ti.

Due to hardware limitations, a single charging head cannot be used for two requests if their start times are separated by D hours or less (i.e. if b > a, then b - a > D is required). Determine the minimum number of charging heads required to satisfy all requests.

Input Format

Line 1: Integers N and D (1 ≤ N ≤ 2·105, 0 ≤ D ≤ 109).
Line 2: N integers t1, t2, ..., tN (0 ≤ ti ≤ 109).

Output Format

Print a single integer: the minimum number of charging heads required.

Sample Testcases

Input 1
6 2
3 1 2 8 7 3
Output 1
4
Input 2
4 5
100 1 50 3
Output 2
2
Note: In sample 1, sorted times are 1, 2, 3, 3, 7, 8 with D = 2. Head 1 takes {1, 7}; Head 2 takes {2, 8}; the two requests at 3 require their own heads, making 4 heads total.
Code copied to clipboard!