CF - Array Destruction

Authors: Kevin Sheng, Jesse Choe

Official Editorial

Solution

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

C++

C++ Implementation

// iostream, vector, set, and algorithm
#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 2000;
int arr_size;
int arr[MAX_SIZE];

Java

Java Implementation

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeMap;
public final class DestroyArray {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));

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!