Official Analysis (C++)

Implementation

Time Complexity: O(MlogN)\mathcal{O}(M\log N)

C++

#include <bits/stdc++.h>
using namespace std;
struct Pasture {
int cost;
int index;
bool had_hay;
bool operator<(const Pasture &other) const {
return cost > other.cost; // For priority queue

Java

import java.io.*;
import java.util.*;
public class FineDining {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new File("dining.in"));
PrintWriter out = new PrintWriter("dining.out");
int n = sc.nextInt();
int m = sc.nextInt();

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!