Three-dimensional energy gap and origin of charge-density wave in kagome superconductor KV3Sb5