Solution 1

Official Editorial (no code)

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

C++

#include <bits/stdc++.h>
using namespace std;
void fail() {
cout << "No\n";
exit(0);
}
int main() {
ios::sync_with_stdio(false);

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!