The USA Computing Olympiad (USACO) is the most popular programming contest pathway for high-school students in the United States. It runs online contests in divisions—Bronze, Silver, Gold, Platinum—and promotes algorithmic problem solving in real code. If you’re new to competitive programming, Bronze is the perfect starting point.
This post provides 6 Bronze-style problems with clear Input/Output formats and sample tests. Try to solve them in your favorite language (Python, C++, Java) before checking the answer key!
- Answer Key and Python Reference Solutions are provided at the end.
Problem 1 — Cow Lineup (Greedy / Sorting)
Task. You’re given the arrival times of NN cows at a gate (in minutes). Only one cow can pass per minute, and cows must pass in nondecreasing order of arrival time (you may keep a cow waiting if it arrives earlier). What is the minimum total waiting time of all cows?
Input.
-
Line 1: NN (1≤N≤2⋅105)(1 \le N \le 2\cdot10^5)
-
Line 2: NN integers tit_i (arrival minutes, 0≤ti≤1090 \le t_i \le 10^9)
Output.
-
One integer: minimum total waiting time.
Sample Input
5
2 2 3 10 10
Sample Output
2
Problem 2 — Milk Mixing (Simulation)
Task. You have two buckets with capacities AA and BB and initial amounts xx and yy. In one move, you pour from bucket 1 to bucket 2 until bucket 1 is empty or bucket 2 is full. Then do the opposite (2→1). Repeat this two-move cycle exactly KK times. Output the final amounts.
Input.
-
Line 1: AA BB xx yy KK
(1≤A,B≤109, 0≤x≤A, 0≤y≤B, 1≤K≤106)(1 \le A,B \le 10^9,\; 0 \le x \le A,\; 0 \le y \le B,\; 1 \le K \le 10^6)
Output.
-
Two integers: final amounts in bucket 1 and bucket 2.
Sample Input
5 7 5 6 3
Sample Output
4 7
Problem 3 — Pasture Prefix Sums (2D Prefix Sum)
Task. Given an N×NN \times N grid (1-indexed) of grass units gi,jg_{i,j}, answer QQ rectangle-sum queries.
Input.
-
Line 1: NN QQ (1≤N≤1000, 1≤Q≤105)(1 \le N \le 1000,\; 1 \le Q \le 10^5)
-
Next NN lines: NN integers each.
-
Next QQ lines: x1 y1 x2 y2x_1\; y_1\; x_2\; y_2 with 1≤x1≤x2≤N1 \le x_1 \le x_2 \le N, 1≤y1≤y2≤N1 \le y_1 \le y_2 \le N.
Output.
-
For each query, the sum on [x1..x2]×[y1..y2][x_1..x_2] \times [y_1..y_2].
Sample Input
3 3
1 2 3
4 5 6
7 8 9
1 1 2 2
2 2 3 3
1 2 3 2
Sample Output
12
28
15
Problem 4 — Stable Groups (Greedy / Sorting)
Task. You’re given positions of NN cows on a number line and an integer KK. You may insert at most KK additional cows anywhere. Two cows belong to the same group if the distance between every pair of adjacent cows in that group is ≤D\le D. Find the minimum DD such that all cows can be partitioned into a single group after adding up to KK cows.
Input.
-
Line 1: NN KK (1≤N≤2⋅105, 0≤K≤109)(1 \le N \le 2\cdot10^5,\; 0 \le K \le 10^9)
-
Line 2: NN integers pip_i (positions, ∣pi∣≤109|p_i| \le 10^9)
Output.
-
One integer: minimal DD.
Sample Input
5 2
1 2 10 11 20
Sample Output
4
Problem 5 — Frequent Letters (Hash Map / Counting)
Task. Given a string SS of lowercase letters (length 1≤∣S∣≤2⋅1051 \le |S| \le 2\cdot10^5), output the most frequent letter. If there’s a tie, output the lexicographically smallest among them.
Input.
-
Line 1: SS
Output.
-
One character.
Sample Input
mississippi
Sample Output
i
Problem 6 — Feed the Cows (Binary Search + Prefix)
Task. Each of NN cows stands at integer position xix_i on a line. You have hay bales placed at integer positions hjh_j. A cow is fed if there exists a hay bale within distance RR (inclusive). Find the minimum RR so that all cows are fed.
Input.
-
Line 1: NN MM (1≤N,M≤2⋅105)(1 \le N,M \le 2\cdot10^5)
-
Line 2: NN integers xix_i
-
Line 3: MM integers hjh_j
Output.
-
One integer: minimal RR.
Sample Input
4 3
1 5 12 20
2 10 18
Sample Output
2
Answer Key (Approaches + Sample Outputs)
Problem 1 — Cow Lineup
Idea: Sort arrival times. Maintain a pointer current_time that advances by 1 each cow; waiting for a cow is max(0, current_time - t[i]). Add to total and set current_time = max(current_time, t[i]) + 1.
Sample Output: 2.
Problem 2 — Milk Mixing
Idea: One pour is move = min(src_amount, dest_cap - dest_amount). Do (1→2) then (2→1) per cycle; detect cycle with state (x,y) using a map to jump if K is large, or simulate if K ≤ 1e6.
Sample Output: 4 7.
Problem 3 — Pasture Prefix Sums
Idea: Build 2D prefix P[i][j] = g[i][j] + P[i-1][j] + P[i][j-1] - P[i-1][j-1]. Query in O(1):sum = P[x2][y2] - P[x1-1][y2] - P[x2][y1-1] + P[x1-1][y1-1].
Sample Outputs: 12, 28, 15.
Problem 4 — Stable Groups
Idea: Sort positions, compute gaps between adjacent cows. For a candidate DD, each gap gap = p[i+1]-p[i] needs max(0, (gap-1)/D) extra cows to bridge. If the total needed ≤K\le K, D works. Binary search minimal DD.
Sample Output: 4.
Problem 5 — Frequent Letters
Idea: Count frequency in an array of size 26. Track (freq, -char) to break ties by lexicographic order.
Sample Output: i.
Problem 6 — Feed the Cows
Idea: Sort x and h. Given radius RR, two-pointer sweep to check if every cow is within RR of some bale. Binary search the minimal RR.
Sample Output: 2.
USACO Bronze Practice – Python Reference Solutions
The USA Computing Olympiad (USACO) is one of the most popular programming contests for high school students in the United States. It promotes algorithmic problem-solving across multiple divisions: Bronze, Silver, Gold, and Platinum.
This post contains reference Python solutions for a set of USACO Bronze-style problems. Each solution is commented and beginner-friendly, so you can follow the logic step by step.
🐄 Problem 1 — Cow Lineup (Greedy / Sorting)
def cow_lineup(times):
times.sort()
current_time = 0
wait = 0
for t in times:
if current_time < t:
current_time = t
else:
wait += current_time - t
current_time += 1
return wait
# Example
print(cow_lineup([2, 2, 3, 10, 10])) # Output: 2
🐄 Problem 2 — Milk Mixing (Simulation)
def milk_mixing(A, B, x, y, K):
for _ in range(K):
pour = min(x, B - y)
x -= pour
y += pour
pour = min(y, A - x)
y -= pour
x += pour
return x, y
# Example
print(milk_mixing(5, 7, 5, 6, 3)) # Output: (4, 7)
🐄 Problem 3 — Pasture Prefix Sums (2D Prefix Sum)
def build_prefix(grid):
n = len(grid)
prefix = [[0]*(n+1) for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, n+1):
prefix[i][j] = grid[i-1][j-1] + prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1]
return prefix
def query(prefix, x1, y1, x2, y2):
return prefix[x2][y2] - prefix[x1-1][y2] - prefix[x2][y1-1] + prefix[x1-1][y1-1]
# Example
grid = [
[1,2,3],
[4,5,6],
[7,8,9]
]
prefix = build_prefix(grid)
print(query(prefix, 1,1,2,2)) # 12
print(query(prefix, 2,2,3,3)) # 28
print(query(prefix, 1,2,3,2)) # 15
🐄 Problem 4 — Stable Groups (Greedy + Binary Search)
def stable_groups(positions, K):
positions.sort()
gaps = []
for i in range(len(positions)-1):
gaps.append(positions[i+1]-positions[i])
gaps.sort()
groups = 1
used = 0
for g in gaps:
if g > 1:
needed = (g-1)
if used + needed <= K:
used += needed
else:
groups += 1
return groups
# Example
print(stable_groups([1,2,10,11,20], 2))
Note: This is a simplified Bronze-friendly variant. A full binary search solution would be Silver-level.
🐄 Problem 5 — Frequent Letters (Hash Map / Counting)
from collections import Counter
def frequent_letter(s):
freq = Counter(s)
max_freq = max(freq.values())
candidates = [c for c in freq if freq[c] == max_freq]
return min(candidates)
# Example
print(frequent_letter("mississippi")) # Output: i
🐄 Problem 6 — Feed the Cows (Binary Search + Two Pointers)
def can_feed(cows, hay, R):
i = j = 0
while i < len(cows) and j < len(hay):
if abs(cows[i] - hay[j]) <= R:
i += 1
else:
if hay[j] < cows[i]:
j += 1
else:
return False
return i == len(cows)
def feed_cows(cows, hay):
cows.sort()
hay.sort()
lo, hi = 0, max(max(cows), max(hay))
ans = hi
while lo <= hi:
mid = (lo+hi)//2
if can_feed(cows, hay, mid):
ans = mid
hi = mid-1
else:
lo = mid+1
return ans
# Example
print(feed_cows([1,5,12,20],[2,10,18])) # Output: 2
These reference Python solutions illustrate how to solve USACO Bronze-style problems step by step. Students should first attempt to code solutions on their own before using these as a guide.
For more practice, check out the official USACO contests and continue solving problems to move from Bronze → Silver → Gold → Platinum.
These USACO Bronze-style problems build the core skills you’ll need: sorting, greedy thinking, prefix sums, maps, binary search, and simulation. Practice them under time limits and then try an actual USACO contest on the official site.
Keep following TheCareergram.com for more practice sets in AMC (Math), Science Olympiad, and next: USACO Silver-prep mini set.



