Greedy Scheduling of Maximum Meetings and Reconstructing Target Arrays via Reverse Operations
Maximum Meetings Attendance
Given a list of meetings where each meeting is represented as [start, end], determine the largest number of meetings you can attend if you can only be in one meeting per day and you may pick any day within the inclusive interval [start, end] to attend that meeting.
Intuition
The key observation is that we want to fin ...
Posted on Thu, 18 Jun 2026 18:22:07 +0000 by cullouch
Merging Fruits and Fence Repair G Solution
[NOIP2004 Advanced Group] Merging Fruits / [USACO06NOV] Fence Repair G
Problem Description
In an orchard, Duoduo has already knocked down all the fruits and divided them into different piles according to their types. Duoduo decides to merge all the fruits into one pile.
Each time, Duoduo can merge two piles together, and the effort consumed equ ...
Posted on Thu, 18 Jun 2026 18:09:18 +0000 by mikeyca
Find the Tournament Champion and Rearrange a Binary Grid
Find the Champion in an Array Game
Given a distinct-integer array arr and an integer k, simulate a game where the first two elements compete in each round. The larger value wins, stays at index 0, and the smaller one is moved to the end. The game ends as soon as any value wins k consecutive rounds; that value is the champion.
Examples
arr = [2 ...
Posted on Sun, 14 Jun 2026 16:51:33 +0000 by adders
Essential Algorithm Templates in C++
Number Theory
Primality Testing via Trial Division
#include <iostream>
using namespace std;
bool isPrime(int num) {
if (num < 2) return false;
for (int d = 2; d <= num / d; ++d)
if (num % d == 0) return false;
return true;
}
int main() {
int queries;
cin >> queries;
while (queries--) {
...
Posted on Sat, 13 Jun 2026 17:12:21 +0000 by sebjlan
Minimum Adjacent Swaps to Balance Bracket Sequences
A bracket string of even length consists of exactly n/2 opening [ and n/2 closing ] characters. The goal is to determine fewest number of arbitrary index swaps required to transform the string into a valid bracket sequence (one where every closing bracket has a matching opening bracket earlier in the string).
Pairs of matched brackets can be t ...
Posted on Fri, 12 Jun 2026 18:11:11 +0000 by razorsedgeuk
Binary Search Templates and Median Optimization for Resource Distribution
Binary Search Implemantation Patterns
Two common binary search variations address different optimization scenarios:
Maximizing Minimum Value
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool validateMin(vector<long>& positions, long min_gap, int removals) {
long prev = 0;
i ...
Posted on Wed, 10 Jun 2026 17:50:35 +0000 by cedartree
Algorithmic Problem Solving Techniques and Implementations
Equalizing Card Piles (Greedy Approach)
To distribute cards equally among $N$ piles, calculate the average number of cards per pile and subtract this value from each pile's count. This transforms the problem into finding the minimum number of moves to zero out the differences. Iterating from left to right, if a pile has a non-zero discrpeancy, ...
Posted on Wed, 10 Jun 2026 16:32:25 +0000 by bdichiara
JOISC2017 Ticket Reservation Problem Solution
Problem Statement:
Given positive integers $n$, $m$, and $m$ triplets $(l_i, r_i, c_i)$, we have an array $a_{1..n}$ initialized with zeros.
For each operation $i = 1, ..., m$, perform the following steps:
Choose any integer $k \in [0, c_i]$.
Add $k$ to all elements $a_j$ where $j \in [l_i, r_i]$.
Add $c_i - k$ to all elements $a_j$ where $j \ ...
Posted on Tue, 09 Jun 2026 17:52:16 +0000 by adunphy
Optimization and Strategy Problems on Sequences and Grids
Resource Redistribution with Asymmetric Operations
Given a sequence (a) of length (n) and two positive integers (x, y) where (y \le x). You may repeatedly pick two elements and transfer resources: subtract (x) from one and add (y) to the other, provided the first remains non‑negative. Determine the maximum possible value of any element after op ...
Posted on Tue, 09 Jun 2026 17:33:25 +0000 by obesechicken13
Maximum Sum Divisible by Three
Given an integer array nums, find and return the maximum sum of elements that is divisible by three.
Examples
Example 1:
Input: nums = [3,6,5,1,8]
Output: 18
Explanation: Choose numbers 3, 6, 1, and 8. Their sum is 18 (the maximum sum divisible by three).
Example 2:
Input: nums = [4]
Output: 0
Explanation: 4 is not divisible by 3, so no number ...
Posted on Tue, 02 Jun 2026 17:22:57 +0000 by JamesThePanda