fork download
  1. package main
  2.  
  3. import (
  4. "bufio"
  5. "os"
  6. "fmt"
  7. "strconv"
  8. "strings"
  9. )
  10.  
  11. func main() {
  12.  
  13. var t int
  14. fmt.Scanln(&t)
  15.  
  16. for i := 0; i < t; i++ {
  17. scanner := bufio.NewScanner(os.Stdin)
  18. var n,k,ans,owns int
  19. owns = 0
  20. ans = 0
  21. fmt.Scanln(&n,&k)
  22.  
  23. scanner.Scan()
  24. s := scanner.Text()
  25. fmt.Println("s=",s)
  26. //s, _ := reader.ReadString('\n')
  27. //s = strings.TrimSpace(s)
  28.  
  29. ai := strings.Split(s," ")
  30.  
  31. for j := 0; j < n; j++ {
  32. a, _ := strconv.Atoi(ai[j])
  33.  
  34. if a >= k && a> 0{
  35. owns += a
  36. }else if a == 0 && owns > 0 {
  37. owns--
  38. ans++
  39. }
  40. }
  41. fmt.Println(ans)
  42. }
  43. }
Success #stdin #stdout 0s 5280KB
stdin
4
2 2
2 0
3 2
3 0 0
6 2
0 3 0 0 0 0
2 5
5 4
stdout
s= 2 0
1
s= 
0
s= 
0
s= 
0