Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Created November 6, 2018 16:36
Show Gist options
  • Select an option

  • Save bastienapp/58af8ccae98c542a33764ca9dc70f6b0 to your computer and use it in GitHub Desktop.

Select an option

Save bastienapp/58af8ccae98c542a33764ca9dc70f6b0 to your computer and use it in GitHub Desktop.
/*******
* Read input from System.in
* Use: System.out.println to ouput your result to STDOUT.
* Use: System.err.println to ouput debugging information to STDERR.
* ***/
package com.isograd.exercise;
import java.util.*;
public class IsoContest {
public static void main( String[] argv ) throws Exception {
Scanner sc = new Scanner(System.in);
int note1 = sc.nextInt();
int note2 = sc.nextInt();
int note3 = sc.nextInt();
int note4 = sc.nextInt();
int note5 = sc.nextInt();
int nbAmis = sc.nextInt();
int nbBesta = sc.nextInt();
TreeMap<Integer, Integer> mapNotes = new TreeMap<>();
for (int i = 0; i < nbAmis; i++) {
int noteA1 = sc.nextInt();
int noteA2 = sc.nextInt();
int noteA3 = sc.nextInt();
int noteA4 = sc.nextInt();
int noteA5 = sc.nextInt();
int noteA6 = sc.nextInt();
int distance = 0;
distance += Math.abs(note1 - noteA1);
distance += Math.abs(note2 - noteA2);
distance += Math.abs(note3 - noteA3);
distance += Math.abs(note4 - noteA4);
distance += Math.abs(note5 - noteA5);
mapNotes.put(distance, noteA6);
}
SortedSet<Integer> keys = new TreeSet<>(mapNotes.keySet());
int totalNotes = 0;
int i = 0;
for (Integer key : keys) {
if (i < nbBesta) {
totalNotes += mapNotes.get(key);
}
i++;
}
int result = (int) Math.floor(totalNotes / nbBesta);
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment