Explanation
For each diamond , we check how many other diamonds can be displayed alongside it in the case, i.e. how many other diamonds falls in the range . Our answer will be the maximum count we find for any diamond.
Implementation
Time Complexity:
with open("diamond.in") as fin:n, k = map(int, fin.readline().split())diamonds = [int(fin.readline()) for _ in range(n)]most = 0"""Iterate through all diamonds and test setting themas the smallest diamond in the case."""for x in diamonds:
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!