USACO Silver 2020 US Open - Social Distancing

Authors: Qi Wang (Java), Tanish Tyagi (C++)

Problem Statement

Official Analysis

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

C++

C++ Implementation

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, m;
pair<ll,ll> intervals[100005];
void setIO(string name, bool includeout=false) { // name is nonempty for USACO file I/O
ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output

Java

import java.util.*;
import java.io.*;
public class socdist{
static int N, M;
static Pair[] P;
public static void main(String[] args) throws IOException{
InputReader in = new InputReader("socdist.in");
N = in.nextInt(); M = in.nextInt(); P = new Pair[M];
for(int i = 0; i<M; i++){

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!