We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
int st = in.nextInt();
int pass = in.nextInt();
int nitro = in.nextInt();
int [] timeSt =new int [st -1];
for (int i =0; i< st-1; i++){
timeSt[i]= in.nextInt();
//System.out.print(" " + timeSt[i]);
}
//System.out.print(st +" "+ pass +" "+ nitro + " " + in.nextInt());
// estacion , max tiempo de espera
int auxT = 0;
int auxE = 0;
int trash = 0;
Map <Integer,Integer> trav = new HashMap<>();
for (int i = 0; i < pass; i ++){
auxT = in.nextInt();
auxE = (in.nextInt()) - 1;
trash = (in.nextInt());
//System.out.println("T: "+ auxT+" ST: "+auxE);
if (!(trav.containsKey(auxE))){
trav.put(auxE, auxT);
}else{
if(trav.get(auxE)< auxT ){
trav.put(auxE, auxT);
// System.out.println("metemos ->T: "+ auxT+" ST: "+auxE);
}
}
}
// nitro
int aux = 0;
for (int i = timeSt.length -1; i>=0; i--){
if (2*nitro <= timeSt[i]){
timeSt[i] -= nitro;
nitro = 0;
break;
}else {
if (timeSt[i] % 2 == 1){
aux = (timeSt[i]-1 / 2);
timeSt[i] = (timeSt[i]+1) /2;
nitro -= nitro;
}
}
}
// se presupone que empezamos enn t=0
long timeTot = 0;
for (int i = 0; i<st-1; i++){
//System.out.println("parada" + i+ "time " + timeTot);
if (i >= 0){ // ojo las estaciones empiezan en st[0],
// cogemos pasajeros
if(trav.containsKey(i)){
if (timeTot < trav.get(i)){// tiempo de espera
//System.out.println(timeTot);
timeTot = trav.get(i); // esperamos a cargar pasajeros
// System.out.println("Esperamos a la carga hasta "+ timeTot+ "en st " + i);
}
// nos desplazamos
// System.out.println(i +"-> " + timeSt[i]);
}
// System.out.println("ST " + i + " Time " + timeTot+ " ST+1 " + timeSt[i]);
timeTot += timeSt[i];
}
}
//System.out.println();
//vuelta al head
for (int i = 0; i<st-1; i++){
timeTot += timeSt[i];
}
System.out.println(timeTot);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Drive
You are viewing a single comment's thread. Return to all comments →
any help to fix this?
import java.io.; import java.util.;
public class Solution {
}