USACO Silver 2016 Open - Diamond Collector

Authors: Nathan Wang, Albert Ye

Official Analysis

C++

C++ Implementation

1#include <bits/stdc++.h>
2
3using namespace std;
4
5int main() {
6 freopen("diamond.in", "r", stdin);
7 freopen("diamond.out", "w", stdout);
8
9 int n, k; cin >> n >> k;
10 int A[n];

Java

Java Implementation

Source: Nick Wu, from the official USACO editorial

1import java.io.*;
2import java.util.*;
3public class diamondS {
4 public static void main(String[] args) throws IOException {
5 BufferedReader br = new BufferedReader(new FileReader("diamond.in"));
6 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
7 StringTokenizer st = new StringTokenizer(br.readLine());
8 int n = Integer.parseInt(st.nextToken());
9 int k = Integer.parseInt(st.nextToken());
10 int[] list = new int[n];

Python

Python Implementation

1import sys
2
3sys.stdin = open("diamond.in", "r")
4sys.stdout = open("diamond.out", "w")
5
6n, k = map(int,input().split())
7a = sorted([int(input()) for i in range(n)])
8
9mx = [0]*(n+1) # maximum number of diamonds assuming i is the smallest diamond
10j = 0

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!

Give Us Feedback on USACO Silver 2016 Open - Diamond Collector!