USACO Bronze 2016 Open - Diamond Collector - Official Solution

Hi all,

I wanted to understand the official solution here:

In the official solution we have this loop:

for (int x : diamonds) {
	int fittable = 0;
	// Get all diamonds larger than x that differ from it by no more than k.
	for (int y : diamonds) {
		if (x <= y && y <= x + k) {
			fittable++;
		}
	}
	most = max(most, fittable);
}

How does this loop avoid the case where x and y are referring to the same exact diamond? Since there is no index check (we only check if x <= y) how does it avoid that case?

It doesn’t; the comment is misleading.

1 Like

Ah thank you - that makes sense (I assumed I was just not understanding the comment). Since fittable is initialised to 0, we want to count the diamond equal to itself too.