USACO Silver 2016 Open - Diamond Collector
Authors: Nathan Wang, Albert Ye
C++
Implementation
#include <bits/stdc++.h>using namespace std;int main() {freopen("diamond.in", "r", stdin);freopen("diamond.out", "w", stdout);int n, k;cin >> n >> k;
Java
Implementation
Source: Nick Wu, from the official USACO editorial
import java.io.*;import java.util.*;public class diamondS {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader(new FileReader("diamond.in"));PrintWriter pw =new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));StringTokenizer st = new StringTokenizer(br.readLine());int n = Integer.parseInt(st.nextToken());int k = Integer.parseInt(st.nextToken());
Python
Implementation
import syssys.stdin = open("diamond.in", "r")sys.stdout = open("diamond.out", "w")n, k = map(int, input().split())a = sorted([int(input()) for i in range(n)])mx = [0] * (n + 1) # maximum number of diamonds assuming i is the smallest diamondj = 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!