Skip to content

The Careergram

From Classroom to Career — We've Got You Covered

Menu
  • Home
  • Career Paths
  • College & Education
  • Test Prep & Admissions
  • Skill Building & Certifications
  • Jobs & Internships
  • Entrepreneurship & Side Hustles
  • Career Transitions
  • Success Stories
  • Tools & Resources
Menu
USACO Practice – Bronze Level (6 Problems with Samples, Answers, Python Reference)

USACO Practice – Bronze Level (6 Problems with Samples, Answers, Python Reference)

Posted on

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 NNN 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: NNN (1≤N≤2⋅105)(1 \le N \le 2\cdot10^5)(1≤N≤2⋅105)

  • Line 2: NNN integers tit_iti​ (arrival minutes, 0≤ti≤1090 \le t_i \le 10^90≤ti​≤109)

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 AAA and BBB and initial amounts xxx and yyy. 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 KKK times. Output the final amounts.

Input.

  • Line 1: AAA BBB xxx yyy KKK
    (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)(1≤A,B≤109,0≤x≤A,0≤y≤B,1≤K≤106)

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 NN×N grid (1-indexed) of grass units gi,jg_{i,j}gi,j​, answer QQQ rectangle-sum queries.

Input.

  • Line 1: NNN QQQ (1≤N≤1000,  1≤Q≤105)(1 \le N \le 1000,\; 1 \le Q \le 10^5)(1≤N≤1000,1≤Q≤105)

  • Next NNN lines: NNN integers each.

  • Next QQQ lines: x1  y1  x2  y2x_1\; y_1\; x_2\; y_2x1​y1​x2​y2​ with 1≤x1≤x2≤N1 \le x_1 \le x_2 \le N1≤x1​≤x2​≤N, 1≤y1≤y2≤N1 \le y_1 \le y_2 \le N1≤y1​≤y2​≤N.

Output.

  • For each query, the sum on [x1..x2]×[y1..y2][x_1..x_2] \times [y_1..y_2][x1​..x2​]×[y1​..y2​].

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 NNN cows on a number line and an integer KKK. You may insert at most KKK 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≤D. Find the minimum DDD such that all cows can be partitioned into a single group after adding up to KKK cows.

Input.

  • Line 1: NNN KKK (1≤N≤2⋅105,  0≤K≤109)(1 \le N \le 2\cdot10^5,\; 0 \le K \le 10^9)(1≤N≤2⋅105,0≤K≤109)

  • Line 2: NNN integers pip_ipi​ (positions, ∣pi∣≤109|p_i| \le 10^9∣pi​∣≤109)

Output.

  • One integer: minimal DDD.

Sample Input

5 2
1 2 10 11 20

Sample Output

4


Problem 5 — Frequent Letters (Hash Map / Counting)

Task. Given a string SSS of lowercase letters (length 1≤∣S∣≤2⋅1051 \le |S| \le 2\cdot10^51≤∣S∣≤2⋅105), output the most frequent letter. If there’s a tie, output the lexicographically smallest among them.

Input.

  • Line 1: SSS

Output.

  • One character.

Sample Input

mississippi

Sample Output

i


Problem 6 — Feed the Cows (Binary Search + Prefix)

Task. Each of NNN cows stands at integer position xix_ixi​ on a line. You have hay bales placed at integer positions hjh_jhj​. A cow is fed if there exists a hay bale within distance RRR (inclusive). Find the minimum RRR so that all cows are fed.

Input.

  • Line 1: NNN MMM (1≤N,M≤2⋅105)(1 \le N,M \le 2\cdot10^5)(1≤N,M≤2⋅105)

  • Line 2: NNN integers xix_ixi​

  • Line 3: MMM integers hjh_jhj​

Output.

  • One integer: minimal RRR.

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 DDD, 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≤K, D works. Binary search minimal DDD.
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 RRR, two-pointer sweep to check if every cow is within RRR of some bale. Binary search the minimal RRR.
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.

Share on Social Media
xfacebookpinterestlinkedintumblrredditemailwhatsapptelegram

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X

Related

You May Also Like

SAT Practice Test 2SAT Practice Test 2 SAT Math Practice Test: Full-Length Section with AnswersSAT Math Practice Test: Full-Length Section with Answers MathCounts Practice – 8 Sample Problems with AnswersMathCounts Practice – 8 Sample Problems with Answers Science Olympiad Practice Quiz – 10 Sample Questions with AnswersScience Olympiad Practice Quiz – 10 Sample Questions with Answers

Most Popular

  • Top Certifications You Can Earn on Coursera, Udemy, and LinkedIn Learning (2026 Guide)
    Top Certifications You Can Earn on Coursera, Udemy, and LinkedIn Learning (2026 Guide)
  • 50 Free Websites to Learn AI Skills in 2026 (Updated & Verified)
    50 Free Websites to Learn AI Skills in 2026 (Updated & Verified)
  • Best AI Jobs for Beginners in 2026 (No Coding Required)
    Best AI Jobs for Beginners in 2026 (No Coding Required)
  • Highest Paying IT Certifications in 2026 (That Employers Actually Want)
    Highest Paying IT Certifications in 2026 (That Employers Actually Want)
  • Top 10 Certifications That Can Boost Your Salary by $20,000 or More in 2026
    Top 10 Certifications That Can Boost Your Salary by $20,000 or More in 2026
  • Carbon Accounting Jobs: Salary, Skills, and How to Start a Career
    Carbon Accounting Jobs: Salary, Skills, and How to Start a Career
  • Internship Cover Letter Examples for Health Sciences Majors
    Internship Cover Letter Examples for Health Sciences Majors
  • We Analyzed 1,000 Graduates – These Majors Regret Their Choice the Most
    We Analyzed 1,000 Graduates – These Majors Regret Their Choice the Most
  • Prompt Engineering for Beginners: Free Learning Roadmap (2026)
    Prompt Engineering for Beginners: Free Learning Roadmap (2026)
  • Top 5 Resume & Cover Letter Builder Tools Compared
    Top 5 Resume & Cover Letter Builder Tools Compared

Most Searched

  • We Asked 100 CEOs: These Are the Skills They Look for in 2026
  • GRE Daily Vocabulary: Day 1 – Top Words & Practice Quiz
  • Top Countries Hiring for Green Jobs in 2026 (High-Paying Opportunities Worldwide)
  • A Complete Guide to Becoming a Remote UX/UI Designer and Earning $100K+
  • 50 Free Websites to Learn AI Skills in 2026 (Updated & Verified)
  • Internship Cover Letter Examples for Health Sciences Majors
  • How to Graduate Debt-Free – Secrets Colleges Don’t Tell You
  • Top In-Demand Internships by College Major (2026 Guide)
  • Top 5 Resume & Cover Letter Builder Tools Compared
  • How to Successfully Transition to a Remote Career: 7 Steps to Start

Recent Posts

  • Solar Energy Careers: Jobs, Salary, and How to Get Started
  • Carbon Accounting Jobs: Salary, Skills, and How to Start a Career
  • How to Become an ESG Analyst (Salary, Skills, and Career Path)
  • Entry-Level Green Jobs That Pay Surprisingly Well (No Experience Required)
  • Best Degrees for Green Jobs in 2026 (High-Paying Environmental Careers Guide)
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms of Use
©2026 The Careergram | Design: Newspaperly WordPress Theme