Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created April 27, 2015 05:02
Show Gist options
  • Save rogerioagjr/ad9117c4b7b03f46b682 to your computer and use it in GitHub Desktop.
Save rogerioagjr/ad9117c4b7b03f46b682 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.Arrays;
public class solucao {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int num,qtd,i,j,x,y;
String[] aux;
aux = in.readLine().split(" ");
num = Integer.parseInt(aux[0]);
qtd = Integer.parseInt(aux[1]);
String[] n = new String[num];
String[] t = new String[qtd];
int[] h = new int[num];
for(i = 0; i < qtd; i++)t[i] = "";
for(i = 0; i < num; i++){
aux = in.readLine().split(" ");
n[i] = aux[0];
h[i] = Integer.parseInt(aux[1]);
}
for(i = 0; i < num - 1; i++){
for(j = i+1; j < num; j++){
if(h[i] > h[j]){
x = h[i];
h[i] = h[j];
h[j] = x;
aux[0] = n[i];
n[i] = n[j];
n[j] = aux[0];
}
}
}
j = 0;
for(i = num - 1; i > -1; i--){
t[j] += n[i] + " ";
j++;
if(j == qtd)j = 0;
}
for(i = 0; i < qtd; i++){
out.write("Time "+(i+1)+"\n");
y = 0;
x = 0;
for(j = 0; j < t[i].length(); j++){
if(t[i].charAt(j) == ' '){
n[y] = t[i].substring(x,j);
y++;
x = j+1;
}
}
Arrays.sort(n,0,y);
for(j = 0; j < y; j++){
out.write(n[j]+"\n");
}
out.write("\n");
}
out.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment