/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Map
<String,Integer
> quantas
= new HashMap
<String,Integer
>(); quantas.put("a", 10);
quantas.put("b", 20);
quantas.put("c", 30);
quantas.put("d", 15);
quantas.put("e", 25);
quantas.put("f", 5);
Comparator
<Map.
Entry<String,Integer
>> comp
= new Comparator
<Map.
Entry<String,Integer
>>() { return a.getValue() < b.getValue() ? -1 :
a.getValue() > b.getValue() ? 1 :
a.getKey().compareTo(b.getKey()); // Desempate
}
};
PriorityQueue
<Map.
Entry<String,Integer
>> fila
= new PriorityQueue
<Map.
Entry<String,Integer
>>(4, comp
);
for ( Map.
Entry<String,Integer
> entry
: quantas.
entrySet() ) { fila.add(entry);
if ( fila.size() > 3 )
fila.poll(); // Remove o menor
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCU1hcDxTdHJpbmcsSW50ZWdlcj4gcXVhbnRhcyA9IG5ldyBIYXNoTWFwPFN0cmluZyxJbnRlZ2VyPigpOwogICAgICAgIHF1YW50YXMucHV0KCJhIiwgMTApOwogICAgICAgIHF1YW50YXMucHV0KCJiIiwgMjApOwogICAgICAgIHF1YW50YXMucHV0KCJjIiwgMzApOwogICAgICAgIHF1YW50YXMucHV0KCJkIiwgMTUpOwogICAgICAgIHF1YW50YXMucHV0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