Optimizing Single-Facility Location on a One-Dimensional Plane in Java
The objective is to identify a specific coordinate along a linear axis that minimizes the cumulative distance to a predefined set of residential points. When mathematical models are constrained to selecting only from the existing data points, the solution converges toward the statistical median. Specifically, for an even number of observations, ...
Posted on Wed, 14 Oct 2026 16:42:03 +0000 by ScoTi
Determining Representability of an Integer as a Sum of 2020 and 2021 Multiples
Given a positive integer $ n $, determine whether it can be expressed as a non-negative integer combination of 2020 and 2021 — that is, whether there exist integers $ a \geq 0 $ and $ b \geq 0 $ such that:
$$
n = 2020a + 2021b
$$
Rewriting the equation reveals a useful structure:
$$
n = 2020(a + b) + b = 2020k + b,
$$
where $ k = a + b $. Since ...
Posted on Wed, 14 Oct 2026 16:39:25 +0000 by Spiz
Merging Segment Trees: Implementation and Applications
Segment Tree Merging Fundamentals
Segment tree merging combines two segment trees into one. The core algorithm processes corresponding nodes:
If either node is empty, return the other
Otherwise, recursively merge left and right subtrees
Node* merge(Node* x, Node* y) {
if (!x) return y;
if (!y) return x;
x->value += y->v ...
Posted on Tue, 13 Oct 2026 16:45:31 +0000 by Dodon
Essential Algorithm Templates for Competitive Programming
Linear Sieve for Prime Numbers (O(2N))
bool composite[N];
int primes[N], prime_count;
void build_sieve(int limit) {
for (int num = 2; num <= limit; num++) {
if (!composite[num]) {
primes[prime_count++] = num;
}
for (int j = 0; j < prime_count && num * primes[j] <= limit; j++) {
...
Posted on Mon, 12 Oct 2026 16:14:11 +0000 by synstealth
Solutions to Educational Codeforces Round 162
This problem requires counting the number of zeros between the first and last occurrence of 1 in an array.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
int n;
cin >> n;
vector<int> arr(n);
int firstOne = -1, lastOne = -1;
for (int i = 0; i < n; i++) {
...
Posted on Wed, 07 Oct 2026 16:56:53 +0000 by basil
Codeforces Round #EDR118 Editorial
A - Long Comparison
To compare two numbers represented as x1 * 10^p1 and x2 * 10^p2, first compare their total digit lengths: len(x1) + p1 vs len(x2) + p2. If unequal, the result is immediate. Otherwise, reduce both exponents by their minimum to ensure at least one becomes zero. Then scale the base integers accordingly and compare directly. Sin ...
Posted on Wed, 07 Oct 2026 16:44:20 +0000 by omniuni
Greedy Algorithm: Minimum Plank Coverage for Barn Stalls
1349. Barn Repair - AcWing
Difficulty: Medium
Time/Memory Limit: 1s / 64MB
Total Accepted: 1275
Total Submissions: 2405
Source: usaco training 1.4
Algorithm: Greedy
Problem Description
During a stormy night, strong winds damaged the roof and doors of Farmer John's barn. The stalls are arranged in a single row, and cows occup ...
Posted on Wed, 07 Oct 2026 16:12:07 +0000 by chris9902
CodeForces 1406 - Codeforces Round #670 (Div. 2) Editorial
Contest Overview
This round was relatively straightforward, so this editorial will focus on both the technical problem solutions and the interesting sequence of events during the contest.
Problem A - Subset Mex
Problem Statement: Given a set a with |a| = n, partition it into two sets A and B to maximize mex(A) + mex(B). Multiple test cases.
Con ...
Posted on Tue, 06 Oct 2026 16:45:21 +0000 by Brendan Nolan
Two Pointer and Sliding Window Techniques for Competitive Programming
Two Pointers
Two pointers is a fundamental technique that uses two references to traverse data structures simultaneously. There are two primary variants:
Collision Pointers (Converging Pointers): Both pointers start from opposite ends and move toward each other.
Fast and Slow Pointers: Both pointers move in the same direction but at different s ...
Posted on Mon, 05 Oct 2026 16:20:51 +0000 by maxf
Programming Contest Solutions and Analysis
Contest Overview
Total Score: 290
Ranking: 3
Problems Solved: 2
Problem Solutions
Problem 1: Interview Screening
Score: 100
**Analysis:**This is a relatively straightforward problem that resembles bucket sorting. The key is to properly handle the conditional checks without mixing them up.
Implementation:
// Store possible outcomes
string result ...
Posted on Sun, 04 Oct 2026 16:07:53 +0000 by dswain