Official Editorial (C++)

Implementation

Time Complexity: O(NX)\mathcal{O}(N\cdot X)

import java.io.*;
import java.util.*;
public class bookShop {
public static void main(String[] args) throws IOException {
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(b.readLine());
int N = Integer.parseInt(st.nextToken());
int X = Integer.parseInt(st.nextToken());

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!