USACO Silver 2017 January - Cow Dance Show

Authors: Óscar Garries, Juheon Rhee, Brad Ma


Official Analysis (Java)

C++

Time Complexity: O(Nlog2N)\mathcal{O}(N\log^2N)

#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("cowdance.in", "r", stdin);
freopen("cowdance.out", "w", stdout);
int n, t;
cin >> n >> t;
int ar[n];

Python

import heapq
with open("cowdance.in") as r:
n, maximum = map(int, r.readline().split())
dance = [int(r.readline()) for _ in range(n)]
left = 1
right = n + 1
while left < right:
mid = (left + right) // 2

Java

import java.io.*;
import java.util.*;
public class CowDanceShow {
static int[] danceTimes;
static int n;
static int maxTime;
static boolean isOk(int stageSize) {
PriorityQueue<Integer> currentDancing = new PriorityQueue<>();

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!