Official Analysis (Java)

Solution

It's a fairly simple solution if you think a little. The only way a participant can move from gold to platinum is if they were not in platinum before the contest but ended up in platinum after the contest.

By similar logic, a participant can move from silver to gold if they were not in gold or platinum before the contest but ended up in gold or platinum afterwards.

Likewise, a participant can move from bronze to silver if they were not in silver, gold, or platinum before the contest but ended up in one of those divisions after the contest.

Implementation

Time Complexity: O(1)\mathcal{O}(1)

C++

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
// initialize file I/O
ios_base::sync_with_stdio(0);
cin.tie(0); // see Fast Input & Output
freopen("promote.in", "r", stdin);
freopen("promote.out", "w", stdout);

Java

import java.io.*;
import java.util.*;
public class PromotionCounting {
public static void main(String[] args) throws IOException {
Kattio io = new Kattio("promote");
int bronzeBefore = io.nextInt();
int bronzeAfter = io.nextInt();
int silverBefore = io.nextInt();
int silverAfter = io.nextInt();

Python

import sys
sys.stdin = open("promote.in", "r")
sys.stdout = open("promote.out", "a")
bronze = [int(a) for a in input().split(" ")]
silver = [int(b) for b in input().split(" ")]
gold = [int(c) for c in input().split(" ")]
platinum = [int(d) for d in input().split(" ")]

Video Solution

By Neo Wang

Video Solution Code

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!