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 Silver Practice – 5 Coding Problems with Samples & Answers

USACO Silver Practice – 5 Coding Problems with Python Solutions

Posted on

The USA Computing Olympiad (USACO) Silver division is the second level after Bronze, where students encounter more advanced algorithmic problems.
Silver requires knowledge of sorting, greedy scheduling, binary search, disjoint set union, prefix sums, and dynamic programming.
This post provides 5 practice problems with Python reference solutions to help students prepare effectively.


🐄 Problem 1 — Hay Bale Stacking (Prefix Sums)

Task: You’re given N barns in a row. Each of K operations adds 1 bale to every barn in a range [a, b]. After all operations, print the final bale count per barn.


Input:
N K
a1 b1
a2 b2
...
aK bK

Output:
N integers, bale counts per barn

Sample Input

5 3
1 2
2 4
3 5

Sample Output

1 2 2 1 1

Python Reference Solution


def hay_bale_stacking(N, operations):
    diff = [0]*(N+2)  # difference array
    for a, b in operations:
        diff[a] += 1
        diff[b+1] -= 1
    result = []
    curr = 0
    for i in range(1, N+1):
        curr += diff[i]
        result.append(curr)
    return result

# Example
print(hay_bale_stacking(5, [(1,2),(2,4),(3,5)]))  # [1, 2, 2, 1, 1]

🎬 Problem 2 — Movie Festival (Greedy Scheduling)

Task: Given start and end times of N movies, find the maximum number you can watch in full without overlap.


Input:
N
s1 e1
s2 e2
...
sN eN

Output:
Max number of movies

Sample Input

3
3 5
4 9
5 8

Sample Output

2

Python Reference Solution


def movie_festival(movies):
    movies.sort(key=lambda x: x[1])  # sort by end time
    count, last_end = 0, 0
    for start, end in movies:
        if start >= last_end:
            count += 1
            last_end = end
    return count

# Example
print(movie_festival([(3,5),(4,9),(5,8)]))  # 2

🏗️ Problem 3 — Road Construction (Graph Connectivity)

Task: You have N towns and M roads added one by one. After each addition, output the number of connected components.


Input:
N M
u1 v1
u2 v2
...
uM vM

Output:
M integers, number of components after each road

Sample Input

4 3
1 2
3 4
2 3

Sample Output

3
2
1

Python Reference Solution


class DSU:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1]*n
        self.components = n

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, a, b):
        ra, rb = self.find(a), self.find(b)
        if ra != rb:
            if self.size[ra] < self.size[rb]:
                ra, rb = rb, ra
            self.parent[rb] = ra
            self.size[ra] += self.size[rb]
            self.components -= 1

def road_construction(N, roads):
    dsu = DSU(N)
    result = []
    for u,v in roads:
        dsu.union(u-1,v-1)  # 0-index
        result.append(dsu.components)
    return result

# Example
print(road_construction(4, [(1,2),(3,4),(2,3)]))  # [3,2,1]

🐄 Problem 4 — Aggressive Cows (Binary Search Placement)

Task: Place N cows in M stalls such that the minimum distance between any two cows is maximized.


Input:
N M
p1 p2 ... pM

Output:
Largest minimum distance

Sample Input

3 5
1 2 8 4 9

Sample Output

3

Python Reference Solution


def can_place(stalls, N, dist):
    count, last = 1, stalls[0]
    for pos in stalls[1:]:
        if pos - last >= dist:
            count += 1
            last = pos
    return count >= N

def aggressive_cows(N, stalls):
    stalls.sort()
    lo, hi = 1, stalls[-1] - stalls[0]
    ans = 0
    while lo <= hi:
        mid = (lo+hi)//2
        if can_place(stalls, N, mid):
            ans = mid
            lo = mid+1
        else:
            hi = mid-1
    return ans

# Example
print(aggressive_cows(3, [1,2,8,4,9]))  # 3

📈 Problem 5 — Longest Increasing Subsequence (DP)

Task: Find the length of the Longest Increasing Subsequence (LIS) in a given array.


Input:
N
a1 a2 ... aN

Output:
Length of LIS

Sample Input

6
10 9 2 5 3 7

Sample Output

3

Python Reference Solution


import bisect

def LIS(arr):
    sub = []
    for x in arr:
        i = bisect.bisect_left(sub, x)
        if i == len(sub):
            sub.append(x)
        else:
            sub[i] = x
    return len(sub)

# Example
print(LIS([10,9,2,5,3,7]))  # 3

✅ Answer Key (Summary)

  • Problem 1: Use difference array + prefix sum. → 1 2 2 1 1
  • Problem 2: Sort by end time, greedy selection. → 2
  • Problem 3: Use DSU (Union-Find). → 3 2 1
  • Problem 4: Binary search on distance with greedy placement. → 3
  • Problem 5: LIS with binary search (O(N log N)). → 3

These USACO Silver-level problems cover essential algorithmic ideas:
prefix sums, greedy scheduling, graph connectivity with DSU, binary search, and dynamic programming (LIS).
By practicing these, students can strengthen their coding skills and get ready to transition from Bronze → Silver.

Keep following TheCareergram.com for more practice papers in AMC (Math), Science Olympiad, and USACO contests with full solutions.

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

USACO Practice – Bronze Level (6 Problems with Samples, Answers, Python Reference)USACO Practice – Bronze Level (6 Problems with Samples, Answers, Python Reference) How to Land a Dream Internship with No Experience (Step-by-Step Guide)How to Land a Dream Internship with No Experience (Step-by-Step Guide) MathCounts Practice – 8 Sample Problems with AnswersMathCounts Practice – 8 Sample Problems with Answers Jobs That Will Disappear by 2030 - Is Yours on the List?Jobs That Will Disappear by 2030 – Is Yours on the List?

Most Popular

  • 50 Free Websites to Learn AI Skills in 2026 (Updated & Verified)
    50 Free Websites to Learn AI Skills in 2026 (Updated & Verified)
  • Highest Paying IT Certifications in 2026 (That Employers Actually Want)
    Highest Paying IT Certifications in 2026 (That Employers Actually Want)
  • 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)
  • Best AI Jobs for Beginners in 2026 (No Coding Required)
    Best AI Jobs for Beginners in 2026 (No Coding Required)
  • 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
  • Best SAT Prep Books Ranked: 2026 Edition (Digital SAT)
    Best SAT Prep Books Ranked: 2026 Edition (Digital SAT)
  • 10 Unbelievable Businesses You Can Start with Just a Laptop and Wi-Fi
    10 Unbelievable Businesses You Can Start with Just a Laptop and Wi-Fi
  • Best Cybersecurity Certifications for Beginners (2026 Roadmap)
    Best Cybersecurity Certifications for Beginners (2026 Roadmap)
  • 10 ATS-Friendly Resume Templates That Work in 2026
    10 ATS-Friendly Resume Templates That Work in 2026
  • Carbon Accounting Jobs: Salary, Skills, and How to Start a Career
    Carbon Accounting Jobs: Salary, Skills, and How to Start a Career

Most Searched

  • Highest Paying Careers in 2026 (No Degree Required!)
  • USACO Practice – Bronze Level (6 Problems with Samples, Answers, Python Reference)
  • From Military to Civilian Careers: 10 High-Potential Jobs for Veterans
  • 5 Remote Career Paths That Will Pay You $100K+ in 2026
  • Top 5 Resume & Cover Letter Builder Tools Compared
  • Solar Energy Careers: Jobs, Salary, and How to Get Started
  • Digital SAT Format Explained: Complete 2026 Guide
  • Best SAT Prep Books Ranked: 2026 Edition (Digital SAT)
  • Best Cybersecurity Certifications for Beginners (2026 Roadmap)
  • SAT Math Practice Test: Full-Length Section with Answers

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