Blue Bridge Cup 2019 Provincial A: Takeout Shop Priority

In the "Bao Le Me" food delivery system, there are N restaurents numbeerd from 1 to N. Each restaurant has a priority value that starts at 0 at time 0. For every time unit: If a restaurant receives no orders, its priority decreases by 1, but never goes below 0. If it receives one or more orders, its priority increases by 2 per order. ...

Posted on Wed, 12 Aug 2026 16:17:15 +0000 by calbolino

Algorithmic Solutions to AtCoder Beginner Contest 057

Problem A: 24-Hour Time Calculation Given the current time $A$ and a duration $B$ in hours, the task is to determine the start time of an event using a 24-hour clock format. Since the clock cycles every 24 hours, the solution involves a simple modular arithmetic operation. The resulting time is calculated as $(A + B) \pmod{24}$. #include < ...

Posted on Mon, 10 Aug 2026 16:46:33 +0000 by Jimmy_uk

Efficient Subarray Range Sum Calculation Using Monotonic Stacks

The objective is to evaluate the following double summation for a sequence $A$ of length $N$: $$ \sum_{L=0}^{N-1} \sum_{R=L}^{N-1} \left( \max_{k \in [L, R]} A[k] - \min_{k \in [L, R]} A[k] \right) $$ A brute-force enumeration of all contiguous segments results in quadratic or cubic complexity, which is insufficient for large inputs. Two linear ...

Posted on Sun, 09 Aug 2026 16:35:03 +0000 by jhlove

Essential Algorithm Templates for Competitive Programming

Sorting Algorithms Quick Sort (Manual Implementation) #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 100010; ll arr[MAXN]; int n; void quickPartition(int left, int right) { if (left >= right) return; int pivotIdx = (left + right) / 2; ll pivotVal = arr[pivotIdx]; int i = left ...

Posted on Sun, 09 Aug 2026 16:16:01 +0000 by godyn

Solving AtCoder Beginner Contest 356 Problems

Problem A: Array Segment Reversal Given an array of integers from 1 to n, reverse a specified segment between indices l and r. #include <iostream> #include <algorithm> using namespace std; int main() { int n, l, r; cin >> n >> l >> r; int arr[n+1]; for(int i=1; i<=n; i++) arr[i] = i; reverse ...

Posted on Sat, 08 Aug 2026 17:00:05 +0000 by Buchead

Small Programming Techniques and Algorithms

For the summation of floor(n/i) from i=1 to n, we can compute it in O(sqrt(n)) time. The curve of n/x for 1 ≤ x ≤ n has non-increasing segments where floor(n/i) remains constant. For any segment [l, r], all values of floor(n/i) are equal, and r divides n. Here's an implementation: for (ll start = 1; start <= n; start++) { ll quotient = n ...

Posted on Sat, 08 Aug 2026 16:39:55 +0000 by pelegk2

Codeforces VP Contest Solutions

A. Omkar and Password Given a sequence of integres, we can merge adjacent disitnct elements into their sum. The goal is to minimize the final sequence length. If all elements are equal, no merges are possible and the result is the original length. Otherwise, we can always reduce the sequence to a single element by repeatedly merging with the ma ...

Posted on Fri, 07 Aug 2026 16:26:07 +0000 by Iceman512

Algorithmic Solutions for Competitive Programming Problems

1. Resource Allocation using Binary Search This problem requires determining the minimum capacity needed to partition a set of resources into a specific number of groups. A binary search approach is suitable here. The goal is to find the smallest value x such that the items can be covered by at most k groups, where each group has a capacity lim ...

Posted on Wed, 05 Aug 2026 16:39:25 +0000 by brianbehrens

Codeforces Round 165 Editorial - Problem Analysis

Problem A: Two Friends There are two possible scenarios: There exists a pair where person A's best friend is B, and B's best friend is A. In this case, just inviting these two individuals suffices. No such mutual friendship exists. If person A's best friend is B, and B's best friend is C, then inviting A, B, and C ensures both A and B attend. ...

Posted on Sat, 01 Aug 2026 17:04:36 +0000 by penguinmasta

Essential 2D Array Algorithms for Competitive Programming

Matrix Rotation Techniques Matrix rotation involves reorganizing elements in a square grid through geometric transformations. The fundamental approach combines transposition with selective reversal operations. Clockwise 90-Degree Rotation The process involves two sequential transformations: first transpose the matrix, then reverse each row hori ...

Posted on Sat, 01 Aug 2026 16:32:16 +0000 by slipmatt2002