Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.002 s | 4 KBi |
#2 |
Correcto
|
0.006 s | 17 KBi |
#3 |
Correcto
|
0.004 s | 4 KBi |
#4 |
Correcto
|
0.001 s | 4 KBi |
#5 |
Correcto
|
0.003 s | 4 KBi |
#6 |
Correcto
|
0.002 s | 4 KBi |
#7 |
Correcto
|
0.004 s | 6 KBi |
#8 |
Correcto
|
0.006 s | 15 KBi |
#9 |
Correcto
|
0.001 s | 4 KBi |
#10 |
Correcto
|
0.002 s | 3 KBi |
#11 |
Correcto
|
0.002 s | 4 KBi |
#12 |
Correcto
|
0.003 s | 6 KBi |
#13 |
Correcto
|
0.005 s | 17 KBi |
#14 |
Correcto
|
0.002 s | 4 KBi |
#15 |
Correcto
|
0.003 s | 4 KBi |
#16 |
Correcto
|
0.002 s | 4 KBi |
#17 |
Correcto
|
0.003 s | 4 KBi |
#18 |
Correcto
|
0.002 s | 3 KBi |
#19 |
Correcto
|
0.005 s | 15 KBi |
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) type Value struct { IsActive bool Sum int64 } func main() { reader := bufio.NewReader(os.Stdin) reader.ReadString('\n') numbers, _ := reader.ReadString('\n') numbers = strings.ReplaceAll(numbers, "\n", "") numbersSeparate := strings.Split(numbers, " ") heights := make(map[int64]Value) var maxValue int64 = 0 beforeValues := make([]int64, 0) for _, value := range numbersSeparate { valueInt, _ := strconv.ParseInt(value, 10, 64) if _, ok := heights[valueInt]; !ok { valHeight := Value{ IsActive: true, Sum: 0, } isExit := false for j := len(beforeValues) - 1; j > -1 && !isExit; j-- { numberBefore := beforeValues[j] if numberBefore >= valueInt { valHeight.Sum += valueInt } else { isExit = true } } heights[valueInt] = valHeight } for key, val := range heights { if heights[key].IsActive { if key > valueInt { val.IsActive = false } else { val.Sum += key } heights[key] = val } if val.Sum > maxValue { maxValue = val.Sum } } beforeValues = append(beforeValues, valueInt) } fmt.Println(maxValue) }