ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2033. Devices

Wrong answer 32
Posted by Nextatix 20 Apr 2015 13:33
import java.io.*;
import java.util.*;
//import java.math.*;

public class Main
{
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
//String[] name = new String[6];
String[] device = new String[6];
int[] price = new int[6];
Map<String,Integer> result = new TreeMap<String,Integer>();
Map<String,Integer> rprice = new TreeMap<String,Integer>();

for(int i=0; i<6; i++) {
in.readLine();
device[i] = in.readLine();
price[i] = Integer.parseInt(in.readLine());

if(!result.containsKey(device[i])) {
result.put(device[i],1);
rprice.put(device[i],price[i]);
}
else {
result.put(device[i],result.get(device[i])+1);
if(price[i]<rprice.get(device[i])) rprice.put(device[i],price[i]);
}
}

int rep = 1, max = 1;
for(int i : new ArrayList<Integer>(result.values())) {
if(max==i) rep++;
if(max<i) { rep = 1; max = i; }
}

if(rep==1) {
for(String i : result.keySet())
if(max==result.get(i)) out.print(i);
}
else {
int min=0;
for(String i : rprice.keySet()) {
if(max==result.get(i)) {
if(min==0) min=rprice.get(i);
else if(min>=rprice.get(i)) min=rprice.get(i);
}
}
for(String i : rprice.keySet()) {
if(min==rprice.get(i)) out.print(i);
}
}
out.flush();
}
}